jQuery fadeIn/fadeOut 循环问题
我正在尝试用循环制作顺序动画......但我无法以顺利的方式完成它(一些“滞后”问题)。
jQuery
var i = 0;
var b = 0;
var fades = function(){$(".caja").stop(0).each(function(){
$(this).delay(i * 500).fadeIn('slow', function(){
$(this).delay(5000).fadeOut('slow', function(){
$(".cajar").delay(1000).each(function(){
$(this).delay(b * 500).fadeIn('slow', function(){
$(this).delay(5000).fadeOut('slow', fades());
});
b++;
});
});
});
i++;
})}
fades();
CSS
.caja{
width: 150px;
height: 150px;
background-color: black;
float: left;
margin: 0 10px 0 0;
display: none;
}
.cajar{
width: 150px;
height: 150px;
background-color: red;
float: left;
margin: 0 10px 0 0;
display: none;
}
.cajav{
width: 150px;
height: 150px;
background-color: green;
float: left;
margin: 0 10px 0 0;
display: none;
}
HTML
<div class="caja"></div>
<div class="caja"></div>
<div class="caja"></div>
<div class="cleaner"></div>
<div class="cajar"></div>
<div class="cajar"></div>
<div class="cajar"></div>
谢谢!
I'm trying to do a sequential animation with a loop....but i can't accomplish it in a smooth way (some "lag" problems).
jQuery
var i = 0;
var b = 0;
var fades = function(){$(".caja").stop(0).each(function(){
$(this).delay(i * 500).fadeIn('slow', function(){
$(this).delay(5000).fadeOut('slow', function(){
$(".cajar").delay(1000).each(function(){
$(this).delay(b * 500).fadeIn('slow', function(){
$(this).delay(5000).fadeOut('slow', fades());
});
b++;
});
});
});
i++;
})}
fades();
CSS
.caja{
width: 150px;
height: 150px;
background-color: black;
float: left;
margin: 0 10px 0 0;
display: none;
}
.cajar{
width: 150px;
height: 150px;
background-color: red;
float: left;
margin: 0 10px 0 0;
display: none;
}
.cajav{
width: 150px;
height: 150px;
background-color: green;
float: left;
margin: 0 10px 0 0;
display: none;
}
HTML
<div class="caja"></div>
<div class="caja"></div>
<div class="caja"></div>
<div class="cleaner"></div>
<div class="cajar"></div>
<div class="cajar"></div>
<div class="cajar"></div>
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,“.each()”调用将几乎同时启动所有淡入淡出(等等),然后所有这些东西在更新“b”时都会互相踩踏。我认为。动画和“延迟”调用之类的东西会立即返回,将要完成的操作放入受影响元素的效果队列中。
也许您可以尝试使用与每个受影响的元素直接关联的“.data()”属性,而不是使用单个“b”。
Well, the ".each()" calls are going to start up all the fades (etc.) pretty much at the same time, and then all those things are going to be stepping on eachother when they update "b". I think. Things like animations and "delay" calls return right away, putting the operations to be done in the effects queue(s) for affected elements.
Maybe you could try, instead of having a single "b", to use a ".data()" attribute directly associated with each affected element.