我如何运行的jQuery的.animate函数下去吗?函数、jQuery、animate

2023-09-10 16:47:13 作者:抚媚不是妖

$(this).css("left","100px");

function endless(){
    $(this).animate({
        left:'-=100px',
    },{
        easing: "linear",
    duration: 5000,
    complete: function() {
        $(this).css('left','100px');
	endless();
        }
    });
};
endless();

这是我试过了,但使用这种方式我不能得到的东西感动。    即时通讯使用jQuery 1.3.2。    有什么建议?

This is what I tried, but using this approach i can't get stuff moving. Im' using jQuery 1.3.2. Any Suggestions?

推荐答案

您拥有的参数来动画错误。它并不需要一个选项哈希,只是实际的选项缓解,持续时间和回调。此外,还需要照顾时,使用。更好地在把它作为参数传递给无尽的功能。

You have the parameters to animate wrong. It doesn't take an options hash, just the actual options for easing, duration, and a callback. Also, you need to take care when using this. Better to pass it in as an argument to the endless function.

$(this).css("left","100px");

function endless(elem){
    $(elem).animate(
        { left:'-=100px' },
        "linear",
        5000,
        function() {
            $(elem).css('left','100px');
            endless(elem);
        }
     );
};
endless(this);