简体   繁体   English

jQuery淡入,一起淡出一些元素

[英]Jquery fade in, fade out some elements together

I need to fade out and fade in some child elements in <div> like in Toni Almeida'a answer: 我需要淡出和淡入<div>中的某些子元素,例如Toni Almeida'a的答案:

Fade in and out image 淡入和淡出图像

 <div class="display" id="slideshow">
            <a class="slice" href="myUrl1">
                <div class="caption">Some text1...</div>
                <img src="AnyUrl1" width="360" height="300"/>
            </a>

            <a class="slice" href="myUrl2">
                <div class="caption">Some text2...</div>
                <img src="AnyUrl2" width="360" height="300"/>
            </a>

            <a class="slice" href="myUrl3">
                <div class="caption">Some text3...</div>
                <img src="AnyUrl3" width="360" height="300"/>
            </a>
           .......
</div>

How should I edit the code in that answer? 我应该如何编辑该答案中的代码?

var count = 1;
var $slideShow = $("#slideshow");
var $prevSlice;
var $nextSlice;
setInterval(function() {
    $prevSlice = $slideShow.find(".slice:nth-child("+count+")");
    count = ($prevSlice.next().length == 0) ? 1 : count+1;
    $nextSlice = $slideShow.find(".slice:nth-child("+count+")");
    $prevSlice.fadeOut();
    $nextSlice.fadeIn();
}, 2000);

Here is a fiddle: http://jsfiddle.net/KA4Zq/308/ 这是一个小提琴: http : //jsfiddle.net/KA4Zq/308/

Is it correct? 这是正确的吗?

Here is my js code modified to work with your html : 这是我的js代码修改为与您的html

var count = 1;
setInterval(function() {
    count = ($("#slideshow").find(".slice:nth-child("+count+")").fadeOut().next().length == 0) ? 1 : count+1;
    $("#slideshow").find(".slice:nth-child("+count+")").fadeIn();
}, 2000);

Fiddle: http://jsfiddle.net/HewAd/ 小提琴: http : //jsfiddle.net/HewAd/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM