簡體   English   中英

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

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

我需要淡出和淡入<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>

我應該如何編輯該答案中的代碼?

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/

這是正確的嗎?

這是我的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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM