简体   繁体   English

我该如何为一个元素设置动画,并且在完成之前不要继续?

[英]how can I animate an element and don't continue till it finished?

I just want to animate element during a game of cards, but the problem is that when I use the animate function the code is continue to run. 我只想在纸牌游戏中对元素进行动画处理,但是问题是当我使用动画功能时,代码会继续运行。 I tried with the promise() and done() function, but for some reason it doesn't help. 我尝试了promise()done()函数,但是由于某种原因,它没有帮助。

Here is what I did: 这是我所做的:

$(document).ready( function() {

    $(".demoCard").animate({
        "margin-top": '-150'
    }, 1000, "easeInSine", function() {
        $(".demoCard").remove();
    });
});

According to the api documentation. 根据api文档。 Your callback is correct. 您的回调是正确的。 Try updating your jQuery api. 尝试更新您的jQuery api。 Maybe you are using an outdated version. 也许您使用的是过时的版本。 If that doesn't work, try removing your easing argument. 如果这样不起作用,请尝试删除缓动参数。 JQuery might be trying to use the easing argument as a callback function. jQuery可能正在尝试将easing参数用作回调函数。 If you need your easing, make sure you have jQuery UI installed and loaded. 如果需要放松,请确保已安装并加载了jQuery UI。 Otherwise, jQuery won't recognize the easing, and try to use easeInOutSine as the callback function. 否则,jQuery将无法识别缓动,并尝试使用easeInOutSine作为回调函数。

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

相关问题 我想生成直到 3 的随机数,但我不想重复它们。 我怎样才能让它工作? - I want to generate random numbers till 3 but i don't want to repeat them. How can i make it work? 在 React/Gatsby 中,当我无权访问文档 object 时,如何使用 CSS 关键帧为粘性 header 设置动画? - In React/Gatsby how can I animate a sticky header using CSS keyframes when I don't have access to the document object? 为什么我不能修改属性 js animate() 应用于元素? - Why can't I modify the property js animate() applies to an element? 元素渲染完成后如何立即运行函数? - How can I run a function as soon as an element has finished rendering? 我怎样才能确保.animate在再次执行之前已经完成 - How can I make sure .animate has finished before performing again 如何使用 jquery 为 li 元素的边框半径设置动画? - How can I animate border-radius of li element with jquery? 添加元素时如何通过展开/折叠 div 来制作动画 - How can I animate by expanding/collapsing a div when adding an element 如何在点击时分别为每个元素设置动画? - How can I animate each element separately on click? 如何为动态添加的背景色设置动画? - How Can I Animate Background Color Dynamically Added Element? 我如何为元素设置动画以使其旋转并通过javascript进行轨道运动 - How can I animate an element to rotate and also orbit with javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM