gpt4 book ai didi

javascript - 如何无限循环动画js

转载 作者:行者123 更新时间:2023-11-28 01:49:12 26 4
gpt4 key购买 nike

我是 jQuery 新手,并且已经成功地为滑冰圣诞老人从一侧到另一侧再返回制作动画,但我找不到循环它的方法

我查看了有关堆栈溢出的示例,但我的经验不足阻止了我将代码调整为我的

            <div class="santa-r"></div>
<div class="santa-l"></div>


<script type="text/javascript">

$(function(){
$('.santa-l').delay(12600).animate({'right': '1800px'}, 5000);
$('.santa-r').delay(3600).animate({'left': '1800px'}, 5000);
});

</script>


.santa-r {
display: block;
overflow: hidden;
position:absolute;
z-index:2;
background: url(../images/anim-santa-right.png) no-repeat;
width: 430px;
height: 500px;
top: 132px;
left: -1600px;
}

.santa-l {
display: block;
overflow: hidden;
position:absolute;
z-index:2;
background: url(../images/anim-santa-left.png) no-repeat;
width: 430px;
height: 500px;
top: 132px;
right: -1600px;
}

最佳答案

试试这个代码:

$(loop); //Call on ready

function loop(){
$('.santa-r, .santa-l').removeAttr('style') //reset the initial position
$('.santa-r').delay(3600).animate({'left': '1800px'}, 5000);
$('.santa-l').delay(12600).animate({'right': '1800px'}, 5000, loop); //Add the loop function in callback
}

关于javascript - 如何无限循环动画js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19931033/

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