Не работает анимация.
Есть 2 элемента
<style> #container { /* описание эемента с id=container*/ width: 200px; height: 200px; background: green; position: relative; } #box { width: 50px; height: 50px; background: red; position: absolute; } </style> <div id="container"> <div id="box"></div> </div> и скрипт к ним: window.onload = function() { var pos = 0; //старотовая позиция var box = document.getElementByld('box'); //выбираем объект по ID var t = setInterval(move, 10); function move() { if(pos >= 150){ clearInterval(t); } else { pos += 1; box.style.left = pos + 'px'; //px = pixels } } }; С телефона тоже самое вбиваю, всё работает. Пишу с брекетсов на компьютере, квадрат просто стоит на месте. В чём проблема? |
Цитата:
Пожалуйста, отформатируйте свой код! Для этого его можно заключить в специальные теги: js/css/html и т.п., например: [js] ... ваш код... [/js] О том, как вставить в сообщение исполняемый javascript и html-код, а также о дополнительных возможностях форматирования - читайте http://javascript.ru/formatting. |
<head>
<style>
#container { /* описание эемента с id=container*/
width: 200px;
height: 200px;
background: green;
position: relative;
}
#box {
width: 50px;
height: 50px;
background: red;
position: absolute;
}
</style>
</head>
<body>
<div id="container">
<div id="box"></div>
</div>
<script>
window.onload = function() {
var pos = 0; //старотовая позиция
var box = document.getElementById('box'); //выбираем объект по ID
var t = setInterval(move, 10);
function move() {
if(pos >= 150){
clearInterval(t);
}
else {
pos += 1;
box.style.left = pos + 'px'; //px = pixels
}
}
};
</script>
</body>
ошибка в коде document.getElementById был неправильно написан! |
| Часовой пояс GMT +3, время: 09:14. |