简体   繁体   English

jQuery 3.5.1 回调 function in.animate() 不工作

[英]jQuery 3.5.1 callback function in .animate() not working

I have a problem making a callback function in .animate() .我在.animate()中进行回调 function 时遇到问题。 The animation goes very smoothly and without problems, but the complete: ()=> part is not working at all. animation 运行非常顺利,没有问题,但complete: ()=>部分根本不起作用。 I've copied this structure from the documentation but it just doesn't want to coop after my changes.我已经从文档中复制了这个结构,但它只是不想在我的更改后合作。 Does anyone know why it doesn't work?有谁知道为什么它不起作用? Is it cause by setInterval?它是由 setInterval 引起的吗? If so, how can I loop this animation?如果是这样,我该如何循环这个 animation?

The code is as follows:代码如下:

setInterval(() => {
    $(".slide")[0].animate({
        "marginLeft": "-100%"
    }, {
        duration: 2000,
        easing: "linear",
        complete: () => {
            console.log("test");
        },
    });
}, 6000);

You will need to make use of the correct selector:您将需要使用正确的选择器:

setInterval(() => {
    $(".slide").eq(0).animate({
        "marginLeft": "-100%"
    }, {
        duration: 2000,
        easing: "linear",
        complete: () => {
            console.log("test");
        },
    });
}, 6000);

When you get element 0 fro mthe Object, it returns the DOM Element and not a jQuery Object.当您从 Object 获取元素0时,它返回 DOM 元素而不是 jQuery Object。 See More:看更多:

https://api.jquery.com/eq/ https://api.jquery.com/eq/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM