2011-08-26 28 views
0

我有一個幻燈片,它唯一改變的照片。我需要在每張照片的頂部添加一個新的div框。目前jQuery代碼只需#slideshow和.active。如何修改它以抓取新的div類「.newbox」(第一張照片爲.newbox1,第二張爲.newbox2等)。每次在不同的照片上出現不同的盒子。這是我的照片幻燈片jQuery代碼:幫我改變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> 

回答

0

你至少在後搞砸了你的HTML。您可以將活動類添加到newbox div元素,然後在幻燈片更改時將其刪除。總之,你不需要使用「主動」類的div。