<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년 전
감사합니다!
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5230 | 13년 전 | 3077 | ||
| 5229 | 13년 전 | 576 | ||
| 5228 | 13년 전 | 622 | ||
| 5227 | 13년 전 | 727 | ||
| 5226 | 13년 전 | 9183 | ||
| 5225 | 13년 전 | 2192 | ||
| 5224 | 13년 전 | 2606 | ||
| 5223 | 13년 전 | 2583 | ||
| 5222 | 13년 전 | 3148 | ||
| 5221 |
visualp
|
13년 전 | 727 | |
| 5220 |
|
13년 전 | 772 | |
| 5219 | 13년 전 | 4666 | ||
| 5218 |
|
13년 전 | 701 | |
| 5217 |
크라이스트
|
13년 전 | 1382 | |
| 5216 | 13년 전 | 1245 | ||
| 5215 | 13년 전 | 1262 | ||
| 5214 | 13년 전 | 1136 | ||
| 5213 | 13년 전 | 689 | ||
| 5212 | 13년 전 | 1368 | ||
| 5211 | 13년 전 | 758 | ||
| 5210 |
visualp
|
13년 전 | 1484 | |
| 5209 |
visualp
|
13년 전 | 1099 | |
| 5208 |
mammoth
|
13년 전 | 737 | |
| 5207 | 13년 전 | 2117 | ||
| 5206 | 13년 전 | 1091 | ||
| 5205 | 13년 전 | 699 | ||
| 5204 |
|
13년 전 | 2269 | |
| 5203 | 13년 전 | 1188 | ||
| 5202 | 13년 전 | 1214 | ||
| 5201 |
kastel
|
13년 전 | 1376 | |
| 5200 | 13년 전 | 1087 | ||
| 5199 | 13년 전 | 573 | ||
| 5198 | 13년 전 | 636 | ||
| 5197 | 13년 전 | 1572 | ||
| 5196 | 13년 전 | 788 | ||
| 5195 | 13년 전 | 1800 | ||
| 5194 | 13년 전 | 1303 | ||
| 5193 | 13년 전 | 617 | ||
| 5192 | 13년 전 | 4066 | ||
| 5191 | 13년 전 | 749 | ||
| 5190 |
|
13년 전 | 1863 | |
| 5189 | 13년 전 | 1202 | ||
| 5188 | 13년 전 | 1550 | ||
| 5187 |
믹스디자인
|
13년 전 | 818 | |
| 5186 |
|
13년 전 | 2392 | |
| 5185 | 13년 전 | 1434 | ||
| 5184 | 13년 전 | 897 | ||
| 5183 | 13년 전 | 1408 | ||
| 5182 | 13년 전 | 685 | ||
| 5181 | 13년 전 | 718 | ||
| 5180 |
프리온관리자
|
13년 전 | 718 | |
| 5179 | 13년 전 | 989 | ||
| 5178 | 13년 전 | 652 | ||
| 5177 | 13년 전 | 576 | ||
| 5176 | 13년 전 | 693 | ||
| 5175 | 13년 전 | 1429 | ||
| 5174 | 13년 전 | 872 | ||
| 5173 | 13년 전 | 606 | ||
| 5172 |
|
13년 전 | 579 | |
| 5171 | 13년 전 | 912 | ||
| 5170 |
KhanSu
|
13년 전 | 708 | |
| 5169 | 13년 전 | 2166 | ||
| 5168 | 13년 전 | 1493 | ||
| 5167 |
sir24
|
13년 전 | 688 | |
| 5166 | 13년 전 | 1753 | ||
| 5165 | 13년 전 | 736 | ||
| 5164 | 13년 전 | 1661 | ||
| 5163 |
|
13년 전 | 1000 | |
| 5162 |
곰도리푸우
|
13년 전 | 4095 | |
| 5161 |
UltraUCC
|
13년 전 | 1231 | |
| 5160 |
|
13년 전 | 886 | |
| 5159 |
그런듯아닌듯
|
13년 전 | 548 | |
| 5158 |
|
13년 전 | 522 | |
| 5157 | 13년 전 | 1657 | ||
| 5156 | 13년 전 | 1163 | ||
| 5155 | 13년 전 | 2653 | ||
| 5154 | 13년 전 | 802 | ||
| 5153 | 13년 전 | 791 | ||
| 5152 |
|
13년 전 | 629 | |
| 5151 | 13년 전 | 838 | ||
| 5150 |
senseme
|
13년 전 | 563 | |
| 5149 |
워드앤코드
|
13년 전 | 1011 | |
| 5148 | 13년 전 | 708 | ||
| 5147 |
프로프리랜서
|
13년 전 | 908 | |
| 5146 | 13년 전 | 2404 | ||
| 5145 |
투코아미디어
|
13년 전 | 1505 | |
| 5144 |
there007
|
13년 전 | 1513 | |
| 5143 | 13년 전 | 1375 | ||
| 5142 | 13년 전 | 2095 | ||
| 5141 |
silky
|
13년 전 | 772 | |
| 5140 |
silky
|
13년 전 | 646 | |
| 5139 |
silky
|
13년 전 | 1987 | |
| 5138 |
silky
|
13년 전 | 588 | |
| 5137 |
silky
|
13년 전 | 616 | |
| 5136 |
silky
|
13년 전 | 900 | |
| 5135 |
silky
|
13년 전 | 623 | |
| 5134 |
silky
|
13년 전 | 478 | |
| 5133 |
|
13년 전 | 846 | |
| 5132 |
복이219
|
13년 전 | 978 | |
| 5131 |
바부바부팅이
|
13년 전 | 1021 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기