gpt4 book ai didi

jquery - 重复动画X次

转载 作者:行者123 更新时间:2023-12-03 22:59:53 25 4
gpt4 key购买 nike

如何更有效地编写此内容?

HTML

<div class="navigation-left">left</div>
<div class="navigation-right">right</div>

JS

$(document).ready(function(){
var offs = 0,
speed = 700;

$('.navigation-left').animate({
left: offs,
opacity: 0
}, speed)
.animate({
left: 70 + offs,
opacity: 100
}, speed)
.animate({
left: offs,
opacity: 0
}, speed)
.animate({
left: 70 + offs,
opacity: 100
}, speed)
.animate({
left: offs,
opacity: 0
}, speed)
.animate({
left: 70 + offs,
opacity: 100
}, speed)
.animate({
left: offs,
opacity: 100
}, speed);

$('.navigation-right').animate({
right: offs,
opacity: 0
}, speed)
.animate({
right: 70 + offs,
opacity: 100
}, speed)
.animate({
right: offs,
opacity: 0
}, speed)
.animate({
right: 70 + offs,
opacity: 100
}, speed)
.animate({
right: offs,
opacity: 0
}, speed)
.animate({
right: 70 + offs,
opacity: 100
}, speed)
.animate({
right: offs,
opacity: 100
}, speed);
});

​请参阅此处的 jsfiddle:http://jsfiddle.net/klawisz/nESMD/

最佳答案

使用 jQuery 和 setTimeout()

(function anim (times){
$('.left').animate({left:70, opacity:0},700).animate({left:0, opacity:1},700);
$('.right').animate({right:70, opacity:0},700).animate({right:0, opacity:1},700);
if(--times) return setTimeout(anim.bind(this, times), 1400);
}( 5 )); // <--- pass initial N of times
.left, .right {position:absolute; width:50px; height:50px; background:red;}
.left {left:0;}
.right {right:0;}
<div class="left"></div>
<div class="right"></div>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>

关于jquery - 重复动画X次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9890998/

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