Показать сообщение отдельно
  #1 (permalink)  
Старый 04.08.2011, 20:05
Аватар для Isaac
Кандидат Javascript-наук
Отправить личное сообщение для Isaac Посмотреть профиль Найти все сообщения от Isaac
 
Регистрация: 03.08.2011
Сообщений: 106

Из-за цикла не работает анимация
Здравсвуйте
Есть код анимации
window.onload = function()
	{
		var distance = 1,
			speed = 0.5,
			li = document.getElementById("lists-r1").children,
			arrayCoords = [0, 26, 53, 78, 104, 130, 156, 182, 208, 234, 260],
			count = 1,
			i = 0,
			arrayCoordsMax = li.length;
			
		for(i; i <= arrayCoordsMax; i ++)
		{
			alert(li[i].offsetTop)
		}		

		function animate()
		{			
			distance = distance + speed;
			document.getElementById("playDiv-r1").style.top = distance + "px";
	
			if(distance == arrayCoords[count])
			{
				setTimeout(animate, 1500);	
				count ++;
			}else
			 	setTimeout(animate, 10);  	
				
			if(distance == 260)
				speed = 0;				
		};		
		animate();
	};
</script>

Сейчас анимация не работает, но если убрать цикл for, то все сразу заработает.
В чем проблема, подскажите ?
Ответить с цитированием