如何在jQuery中永远运行.animate函数?
这是我尝试过的,但使用这种方法我无法让东西移动。 我正在使用jQuery 1.3.2。如何在jQuery中永远运行.animate函数?,jquery,ajax,animation,jquery-1.3.2,Jquery,Ajax,Animation,Jquery 1.3.2,这是我尝试过的,但使用这种方法我无法让东西移动。 我正在使用jQuery 1.3.2。 有什么建议吗?您需要从回调函数中调用unfinal() $(this).css("left","100px"); function endless(){ $(this).animate({ left:'-=100px', },{ easing: "linear", duration: 5000, complete: function() {
有什么建议吗?您需要从回调函数中调用unfinal()
$(this).css("left","100px");
function endless(){
$(this).animate({
left:'-=100px',
},{
easing: "linear",
duration: 5000,
complete: function() {
$(this).css('left','100px');
endless();
}
});
};
endless();
您需要将
$(this)
替换为要设置动画的元素选择器。要设置动画的参数错误。它不需要选项散列,只需要缓和、持续时间和回调的实际选项。此外,使用此
时需要小心。最好将其作为参数传递给无穷函数
function endless(item) {
$(item).animate({"left": "-=100px"}, 5000, "linear", function(){
$(item).css("left","100px");
endless(item);
});
}
endless($(".myBox"));
太好了!这正是我要找的但现在 我终于想出了如何切换它。使用以下函数,调用“无止境”(0)停止,调用“无止境”(1)启用动画循环
$(this).css("left","100px");
function endless(elem){
$(elem).animate(
{ left:'-=100px' },
"linear",
5000,
function() {
$(elem).css('left','100px');
endless(elem);
}
);
};
endless(this);
thanx为初始代码
//loop animation forever
//args: takes 1 to loop, 0 to stop
function endless(loop)
{
//animate forever
if (loop==1)
{
$('#alink').animate(
{'opacity':'toggle'},
1000,
function () { endless(1) }
);
}
//stop animation
else
{
$('#alink').css('opacity',1).stop();
}
};
//sample call
$('#alink').toggle(function(){ endless(1) },function(){ endless(0) });