我正在尝试编写一个javascript应用程序,它在网页上对动态创建的div进行排序,一切正常,它按照应有的方式对其进行排序,但是我希望它为div设置动画,因为它们因排序而改变位置,我有执行此操作的代码,但它移动得太快,我能看到div移动的唯一方法是,如果我在动画代码中放置一个警告,如下所示:
function moveAnimation(to,from){
mover1.style.backgroundColor = "rgba(255,100,175,0.8)";
mover2.style.backgroundColor = "rgba(255,100,175,0.8)";
mover1.style.top = parseInt(mover1.style.top) + 10 + 'px';
mover2.style.top = parseInt(mover2.style.top) - 10 + 'px';
from = parseInt(mover1.style.top);
if(from != to && from < to)
{
//alert("TO : " + to + " From : " + from); //This makes it pause so that I can see the divs move
animate = setTimeout(moveAnimation(to,from),1000)
}
else
{
//alert("RET");
return;
}
}
我称之为:
mover1 = document.getElementById(moving1.id);
mover2 = document.getElementById(moving2.id);
var from = parseInt(in1.style.top);
var to = parseInt(in2.style.top);
moveAnimation(to,from);
当警报到位时,我可以看到它们一帧一帧地移动,它正在按照我的意愿行事,但是这一切都发生在眨眼间,div突然被分类,我希望看到它们慢慢移动,为什么我的代码没有这样做的任何想法?