【问题标题】:Jquery fade in, fade out some elements togetherjquery淡入淡出一些元素一起
【发布时间】:2013-11-04 15:18:03
【问题描述】:

我需要在 <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>

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

【问题讨论】:

  • 你想同时淡入/淡出整个 div 吗?
  • 是的,淡出/淡入所有元素组(div、a 和图像)整个 div。

标签: javascript jquery fadein fade fadeout


【解决方案1】:
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/

对吗?

【讨论】:

    【解决方案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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多