【问题标题】:Help me change jquery slideshow to add additional class帮我更改 jquery 幻灯片以添加其他类
【发布时间】:2011-08-26 15:42:15
【问题描述】:

我有一个幻灯片,它只是改变照片。我需要在每张照片的顶部添加一个新的 div 框。目前jquery 代码只需要#slideshow 和.active。如何修改它以获取新的 div 类“.newbox”(第一张照片为 .newbox1,第二张照片为 .newbox2,依此类推)。每次不同的盒子必须出现在不同的照片之上。这是我的照片幻灯片 jquery 代码:

function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

</script>

我的html:

div id="slideshow">
   <div class="active">
        <a href="http://www.mylink.com/" target="_blank"><img src="http://route/img.jpg" alt="alt" /></a>

    <div class="newbox1"></div>
div class="newbox2"></div>
div class="newbox3"></div>
div class="newbox4"></div>
div class="newbox5"></div>
    </div>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    您至少在帖子中弄乱了您的 HTML。您可以将活动类添加到新框 div 元素,然后在更改幻灯片时将其删除。总之,您不需要具有“活动”类的 div。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多