2

<div>我需要在 Toni Almeida'a 回答中淡出和淡入一些子元素:

淡入淡出图像

 <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>

我应该如何编辑该答案中的代码?

4

2 回答 2

2

这是我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);

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

于 2013-10-25T16:29:23.850 回答
2
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);

这是一个小提琴:http: //jsfiddle.net/KA4Zq/308/

这是对的吗?

于 2013-10-25T16:18:56.740 回答