<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년 전
감사합니다!
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4830 |
임페리얼웹
|
13년 전 | 1356 | |
| 4829 |
임페리얼웹
|
13년 전 | 702 | |
| 4828 | 13년 전 | 3460 | ||
| 4827 |
|
13년 전 | 1220 | |
| 4826 | 13년 전 | 2730 | ||
| 4825 | 13년 전 | 1065 | ||
| 4824 |
gnuskin쩜net
|
13년 전 | 756 | |
| 4823 | 13년 전 | 808 | ||
| 4822 |
visualp
|
13년 전 | 679 | |
| 4821 |
다케미카코
|
13년 전 | 1255 | |
| 4820 | 13년 전 | 1343 | ||
| 4819 | 13년 전 | 2657 | ||
| 4818 |
크라이스트
|
13년 전 | 4234 | |
| 4817 |
임페리얼웹
|
13년 전 | 694 | |
| 4816 | 13년 전 | 3257 | ||
| 4815 |
하모니칼수
|
13년 전 | 640 | |
| 4814 | 13년 전 | 1103 | ||
| 4813 | 13년 전 | 700 | ||
| 4812 |
임페리얼웹
|
13년 전 | 1083 | |
| 4811 |
임페리얼웹
|
13년 전 | 1826 | |
| 4810 | 13년 전 | 1142 | ||
| 4809 | 13년 전 | 617 | ||
| 4808 | 13년 전 | 1277 | ||
| 4807 |
너는나의봄이다
|
13년 전 | 893 | |
| 4806 | 13년 전 | 1288 | ||
| 4805 | 13년 전 | 1767 | ||
| 4804 | 13년 전 | 1066 | ||
| 4803 |
한번잘해보자
|
13년 전 | 712 | |
| 4802 | 13년 전 | 1902 | ||
| 4801 |
꼬꼬아부지
|
13년 전 | 1182 | |
| 4800 | 13년 전 | 764 | ||
| 4799 |
|
13년 전 | 705 | |
| 4798 | 13년 전 | 1066 | ||
| 4797 |
한번잘해보자
|
13년 전 | 605 | |
| 4796 | 13년 전 | 1716 | ||
| 4795 | 13년 전 | 994 | ||
| 4794 |
|
13년 전 | 1013 | |
| 4793 |
|
13년 전 | 649 | |
| 4792 | 13년 전 | 1287 | ||
| 4791 | 13년 전 | 2094 | ||
| 4790 |
|
13년 전 | 612 | |
| 4789 |
한번잘해보자
|
13년 전 | 510 | |
| 4788 |
|
13년 전 | 683 | |
| 4787 | 13년 전 | 3276 | ||
| 4786 |
한번잘해보자
|
13년 전 | 745 | |
| 4785 | 13년 전 | 1299 | ||
| 4784 | 13년 전 | 1074 | ||
| 4783 |
|
13년 전 | 719 | |
| 4782 | 13년 전 | 7729 | ||
| 4781 |
크라운엠버서더
|
13년 전 | 1101 | |
| 4780 | 13년 전 | 1750 | ||
| 4779 | 13년 전 | 750 | ||
| 4778 | 13년 전 | 1085 | ||
| 4777 | 13년 전 | 911 | ||
| 4776 | 13년 전 | 1887 | ||
| 4775 | 13년 전 | 3318 | ||
| 4774 | 13년 전 | 1530 | ||
| 4773 | 13년 전 | 3236 | ||
| 4772 | 13년 전 | 1409 | ||
| 4771 | 13년 전 | 3854 | ||
| 4770 | 13년 전 | 1400 | ||
| 4769 | 13년 전 | 894 | ||
| 4768 | 13년 전 | 1864 | ||
| 4767 | 13년 전 | 2643 | ||
| 4766 | 13년 전 | 1562 | ||
| 4765 | 13년 전 | 1375 | ||
| 4764 | 13년 전 | 3132 | ||
| 4763 | 13년 전 | 1161 | ||
| 4762 |
|
13년 전 | 716 | |
| 4761 | 13년 전 | 1608 | ||
| 4760 | 13년 전 | 843 | ||
| 4759 |
NTYPE
|
13년 전 | 5167 | |
| 4758 |
프로프리랜서
|
13년 전 | 823 | |
| 4757 |
프로프리랜서
|
13년 전 | 1208 | |
| 4756 | 13년 전 | 806 | ||
| 4755 |
원시인교주
|
13년 전 | 831 | |
| 4754 |
there007
|
13년 전 | 948 | |
| 4753 | 13년 전 | 1764 | ||
| 4752 |
세상의중심
|
13년 전 | 1571 | |
| 4751 | 13년 전 | 1298 | ||
| 4750 | 13년 전 | 1496 | ||
| 4749 |
또다른세상
|
13년 전 | 3652 | |
| 4748 | 13년 전 | 761 | ||
| 4747 |
cula100jak
|
13년 전 | 1647 | |
| 4746 | 13년 전 | 1474 | ||
| 4745 |
|
13년 전 | 613 | |
| 4744 |
designcity
|
13년 전 | 739 | |
| 4743 | 13년 전 | 616 | ||
| 4742 |
|
13년 전 | 8346 | |
| 4741 | 13년 전 | 833 | ||
| 4740 | 13년 전 | 1637 | ||
| 4739 | 13년 전 | 1307 | ||
| 4738 |
|
13년 전 | 740 | |
| 4737 |
Xerro
|
13년 전 | 483 | |
| 4736 | 13년 전 | 3720 | ||
| 4735 |
keith
|
13년 전 | 534 | |
| 4734 |
|
13년 전 | 686 | |
| 4733 | 13년 전 | 1743 | ||
| 4732 |
|
13년 전 | 1244 | |
| 4731 |
|
13년 전 | 1294 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기