javascript - jquery 淡入、淡出一些元素一起

标签 javascript jquery fadein fade fadeout

我需要淡出和淡入 <div> 中的一些子元素就像托尼·阿尔梅达的回答一样:

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>

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

最佳答案

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

关于javascript - jquery 淡入、淡出一些元素一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19590956/

相关文章:

javascript - 如何获取div中包含的字符串

javascript - 为什么这个函数console.log 20次而不是一次?

jquery - 服务器端模板、客户端模板 - 自动转换?

jQuery SlideUp 动画显示更多内容

javascript - Fengyuanchen Datepicker - 箭头上一个/下一个

javascript - 使用 Bootstrap buttons-checkbox 伪造复选框行为?

javascript - 除了第一次,jQuery 对象永远不会改变

jquery - 如何使用 jQuery 选择器

dialog - Libgdx - 如何让对话框淡出而不是整个舞台?

javascript - 带有淡入和淡出的 map 信息