gpt4 book ai didi

jquery - 如何循环播放 jQuery div 动画?

转载 作者:行者123 更新时间:2023-12-03 22:44:01 24 4
gpt4 key购买 nike

我正在尝试实现一个带有无限循环的 jQuery 函数来为 div 制作动画。我不知道该怎么做。这是我的代码:

$(document).ready(function () {
$('#divers').animate({
'margin-top': '90px'
}, 6000).animate({
'margin-top': '40px'
}, 6000);
});

最佳答案

将执行完整动画的代码放入函数中,然后将该函数作为回调参数传递给最后一个动画。类似...

$(document).ready(function() {   
function animateDivers() {
$('#divers').animate(
{'margin-top':'90px'}
,6000
)
.animate(
{'margin-top':'40px'}
,6000
,animateDivers //callback the function, to restart animation cycle
);
}

animateDivers(); //call, to start the animation
});

关于jquery - 如何循环播放 jQuery div 动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com