[英]fade in a series of divs then fade out the previous one
So using jquery, I got a bit of javascript to fade in a series of divs over a certain amount of time. 因此,使用jquery时,我得到了一些javascript,可以在一定时间内淡入一系列div。 Now I want to fade out the previous div. 现在,我要淡出上一个div。 Would I be right in putting a fade out function as a call back in the fade in function? 我是否正确地将淡出功能作为淡入功能的回调?
So it would look like this. 所以看起来像这样。
<script type="text/javascript">
$(function() {
$("div").each(function(i, e) {
$(this).delay(i*400).fadeIn(
$(this).delay(i*400).fadeOut);
});
});
</script>
Would that be right or am I doing it wrong? 那是对的还是我做错了?
You have a few syntax problems, the callback should be like so: 您有一些语法问题,回调应如下所示:
$("div").each(function(i, e) {
$(this).delay(i*400).fadeIn(function() {
$(this).delay(i*400).fadeOut();
});
});
Demo: http://jsfiddle.net/tymeJV/FJMa4/ 演示: http : //jsfiddle.net/tymeJV/FJMa4/
Try this, if you need to cycle through and fixed syntax. 如果需要循环浏览并修复语法,请尝试此操作。
var arrDivs = $("div").get(); //Get all the divs into an array
function fade()
{
var div = arrDivs.shift(); //get the top div
var $this = $(div);
arrDivs.push(div); //push it to the end for cycle to repeat
$this.delay($this.index()*400).fadeIn(function(){ //get the index to calculate the delay time.
$this.delay($this.index()*400).fadeOut(function(){
window.setTimeout(fade,1000);
});
});
}
fade();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.