<script>
function nextRandomInteger(limit) {
return Math.round(Math.random() * limit);
}
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function randomAlphabet() {
return alphabet.charAt(nextRandomInteger(25));
}
function randomSpeed(maxSpeed) {
return Math.random() * maxSpeed - Math.random() * maxSpeed;
}
var canvasWidth = 700;
var canvasHeight = 500;
function MovingText() {
function nextRandomInteger(limit) {
return Math.round(Math.random() * limit);
}
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function randomAlphabet() {
return alphabet.charAt(nextRandomInteger(25));
}
function randomSpeed(maxSpeed) {
return Math.random() * maxSpeed - Math.random() * maxSpeed;
}
var canvasWidth = 700;
var canvasHeight = 500;
function MovingText() {
this.x = nextRandomInteger(canvasWidth);
this.y = nextRandomInteger(canvasHeight);
this.vX = randomSpeed(10);
this.vY = randomSpeed(10);
this.body = document.createElement('h1');
this.body.innerHTML = randomAlphabet();
this.body.style.position = 'absolute';
MovingText.prototype.move = function () {
}
this.y = nextRandomInteger(canvasHeight);
this.vX = randomSpeed(10);
this.vY = randomSpeed(10);
this.body = document.createElement('h1');
this.body.innerHTML = randomAlphabet();
this.body.style.position = 'absolute';
MovingText.prototype.move = function () {
}
if (this.x < 0 || this.x > canvasWidth) {this.vX *= -1;}
if (this.y < 0 || this.y > canvasHeight) {this.vY *= -1;}
this.x += this.vX;
this.y += this.vY;
this.body.style.left = this.x + 'px';
this.body.style.top = this.y + 'px';
};
window.onload = function () {
if (this.y < 0 || this.y > canvasHeight) {this.vY *= -1;}
this.x += this.vX;
this.y += this.vY;
this.body.style.left = this.x + 'px';
this.body.style.top = this.y + 'px';
};
window.onload = function () {
var movingTexts = [];
for (var i = 0; i < 100; i++) {
movingTexts.push(new MovingText());
}
setInterval(function () {
for (var i in movingTexts) {
movingTexts[i].move();
}
}, 1000 / 60);
};
</script>
for (var i = 0; i < 100; i++) {
movingTexts.push(new MovingText());
}
setInterval(function () {
for (var i in movingTexts) {
movingTexts[i].move();
}
}, 1000 / 60);
};
</script>
오류도 없는데 빈화면으로밖에 나오질않네요...
뭐가문제인가요?
댓글 2개
jay420
13년 전
소스가 약간씩 모자라거나 열고 닫는 부분이 잘못 되어있네요.
소스를 작성하실때 function 의 시작과 끝을 잘 파악하셔야 하고 무조건 따라 작성하시기 보다는 코드의 흐름을 파악하시고 작성하시는것이 좋을 것 같습니다.
완성소스는 아래와 같습니다.
(참고문헌 : 모던 웹을 위한 javascript jQuery 입문 (윤인성 저) )
<!DOCTYPE html>
<html>
<head>
<script>
function nextRandomInteger(limit) {
return Math.round(Math.random() * limit);
}
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function randomAlphabet() {
return alphabet.charAt(nextRandomInteger(25));
}
function randomSpeed(maxSpeed) {
return Math.random() * maxSpeed - Math.random() * maxSpeed;
}
</script>
<script>
var canvasWidth = 700;
var canvasHeight = 500;
function MovingText() {
this.x = nextRandomInteger(canvasWidth);
this.y = nextRandomInteger(canvasHeight);
this.vX = randomSpeed(10);
this.vY = randomSpeed(10);
this.body = document.createElement('h1');
this.body.innerHTML = randomAlphabet();
this.body.style.position = 'absolute';
document.body.appendChild(this.body);
}
MovingText.prototype.move = function () {
if (this.x < 0 || this.x > canvasWidth) {this.vX *= -1;}
if (this.y < 0 || this.y > canvasHeight) {this.vY *= -1;}
this.x += this.vX;
this.y += this.vY;
this.body.style.left = this.x + 'px';
this.body.style.top = this.y + 'px';
};
</script>
<script>
window.onload = function () {
var movingTexts = [];
for (var i = 0; i < 100; i++) {
movingTexts.push(new MovingText());
}
setInterval(function () {
for (var i in movingTexts) {
movingTexts[i].move();
}
}, 1000 / 60);
};
</script>
</head>
<body>
</body>
</html>
소스를 작성하실때 function 의 시작과 끝을 잘 파악하셔야 하고 무조건 따라 작성하시기 보다는 코드의 흐름을 파악하시고 작성하시는것이 좋을 것 같습니다.
완성소스는 아래와 같습니다.
(참고문헌 : 모던 웹을 위한 javascript jQuery 입문 (윤인성 저) )
<!DOCTYPE html>
<html>
<head>
<script>
function nextRandomInteger(limit) {
return Math.round(Math.random() * limit);
}
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
function randomAlphabet() {
return alphabet.charAt(nextRandomInteger(25));
}
function randomSpeed(maxSpeed) {
return Math.random() * maxSpeed - Math.random() * maxSpeed;
}
</script>
<script>
var canvasWidth = 700;
var canvasHeight = 500;
function MovingText() {
this.x = nextRandomInteger(canvasWidth);
this.y = nextRandomInteger(canvasHeight);
this.vX = randomSpeed(10);
this.vY = randomSpeed(10);
this.body = document.createElement('h1');
this.body.innerHTML = randomAlphabet();
this.body.style.position = 'absolute';
document.body.appendChild(this.body);
}
MovingText.prototype.move = function () {
if (this.x < 0 || this.x > canvasWidth) {this.vX *= -1;}
if (this.y < 0 || this.y > canvasHeight) {this.vY *= -1;}
this.x += this.vX;
this.y += this.vY;
this.body.style.left = this.x + 'px';
this.body.style.top = this.y + 'px';
};
</script>
<script>
window.onload = function () {
var movingTexts = [];
for (var i = 0; i < 100; i++) {
movingTexts.push(new MovingText());
}
setInterval(function () {
for (var i in movingTexts) {
movingTexts[i].move();
}
}, 1000 / 60);
};
</script>
</head>
<body>
</body>
</html>
13년 전
감사합니다!
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5030 | 13년 전 | 785 | ||
| 5029 | 13년 전 | 465 | ||
| 5028 | 13년 전 | 731 | ||
| 5027 | 13년 전 | 1318 | ||
| 5026 | 13년 전 | 548 | ||
| 5025 | 13년 전 | 1370 | ||
| 5024 | 13년 전 | 425 | ||
| 5023 | 13년 전 | 662 | ||
| 5022 | 13년 전 | 430 | ||
| 5021 | 13년 전 | 667 | ||
| 5020 | 13년 전 | 517 | ||
| 5019 | 13년 전 | 860 | ||
| 5018 | 13년 전 | 906 | ||
| 5017 | 13년 전 | 783 | ||
| 5016 | 13년 전 | 2629 | ||
| 5015 | 13년 전 | 416 | ||
| 5014 | 13년 전 | 677 | ||
| 5013 | 13년 전 | 588 | ||
| 5012 |
JacobJeon
|
13년 전 | 1075 | |
| 5011 | 13년 전 | 806 | ||
| 5010 | 13년 전 | 1443 | ||
| 5009 |
JacobJeon
|
13년 전 | 1804 | |
| 5008 | 13년 전 | 1152 | ||
| 5007 | 13년 전 | 3017 | ||
| 5006 |
|
13년 전 | 1308 | |
| 5005 | 13년 전 | 700 | ||
| 5004 | 13년 전 | 2107 | ||
| 5003 | 13년 전 | 2534 | ||
| 5002 | 13년 전 | 388 | ||
| 5001 | 13년 전 | 520 | ||
| 5000 | 13년 전 | 427 | ||
| 4999 | 13년 전 | 526 | ||
| 4998 | 13년 전 | 474 | ||
| 4997 | 13년 전 | 661 | ||
| 4996 | 13년 전 | 1919 | ||
| 4995 | 13년 전 | 393 | ||
| 4994 | 13년 전 | 384 | ||
| 4993 | 13년 전 | 529 | ||
| 4992 | 13년 전 | 503 | ||
| 4991 | 13년 전 | 388 | ||
| 4990 | 13년 전 | 710 | ||
| 4989 | 13년 전 | 653 | ||
| 4988 | 13년 전 | 402 | ||
| 4987 | 13년 전 | 422 | ||
| 4986 | 13년 전 | 1382 | ||
| 4985 | 13년 전 | 665 | ||
| 4984 | 13년 전 | 1047 | ||
| 4983 | 13년 전 | 413 | ||
| 4982 |
쥬드125
|
13년 전 | 1019 | |
| 4981 | 13년 전 | 548 | ||
| 4980 | 13년 전 | 419 | ||
| 4979 | 13년 전 | 694 | ||
| 4978 | 13년 전 | 2184 | ||
| 4977 |
atria
|
13년 전 | 865 | |
| 4976 | 13년 전 | 1532 | ||
| 4975 | 13년 전 | 440 | ||
| 4974 | 13년 전 | 467 | ||
| 4973 | 13년 전 | 708 | ||
| 4972 | 13년 전 | 462 | ||
| 4971 | 13년 전 | 1393 | ||
| 4970 | 13년 전 | 370 | ||
| 4969 | 13년 전 | 423 | ||
| 4968 | 13년 전 | 732 | ||
| 4967 | 13년 전 | 533 | ||
| 4966 | 13년 전 | 446 | ||
| 4965 | 13년 전 | 588 | ||
| 4964 | 13년 전 | 591 | ||
| 4963 | 13년 전 | 428 | ||
| 4962 | 13년 전 | 2255 | ||
| 4961 | 13년 전 | 1350 | ||
| 4960 | 13년 전 | 1236 | ||
| 4959 | 13년 전 | 430 | ||
| 4958 | 13년 전 | 383 | ||
| 4957 | 13년 전 | 472 | ||
| 4956 | 13년 전 | 702 | ||
| 4955 | 13년 전 | 494 | ||
| 4954 | 13년 전 | 1068 | ||
| 4953 | 13년 전 | 1160 | ||
| 4952 | 13년 전 | 755 | ||
| 4951 |
sjsmsrjfflauswnrsmse
|
13년 전 | 880 | |
| 4950 | 13년 전 | 1912 | ||
| 4949 | 13년 전 | 2223 | ||
| 4948 | 13년 전 | 5529 | ||
| 4947 | 13년 전 | 417 | ||
| 4946 | 13년 전 | 852 | ||
| 4945 | 13년 전 | 407 | ||
| 4944 | 13년 전 | 608 | ||
| 4943 |
마당쇠2000
|
13년 전 | 1257 | |
| 4942 |
cula100jak
|
13년 전 | 829 | |
| 4941 | 13년 전 | 476 | ||
| 4940 | 13년 전 | 575 | ||
| 4939 | 13년 전 | 419 | ||
| 4938 | 13년 전 | 568 | ||
| 4937 | 13년 전 | 1505 | ||
| 4936 |
techer
|
13년 전 | 1854 | |
| 4935 | 13년 전 | 726 | ||
| 4934 | 13년 전 | 961 | ||
| 4933 | 13년 전 | 2049 | ||
| 4932 |
kajama78
|
13년 전 | 964 | |
| 4931 | 13년 전 | 989 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기