开发者

How to attach a new div to my jquery code?

开发者 https://www.devze.com 2023-03-31 08:06 出处:网络
I have a slideshow, its only changing photos. Now I need to add a new different div box on top of each photo. At the moment jquery code takes just #slideshow and .active. How to amend it to grab also

I have a slideshow, its only changing photos. Now I need to add a new different div box on top of each photo. At the moment jquery code takes just #slideshow and .active. How to amend it to grab also new different ".newbox" (.newbox1 for first photo, .newbox2 for second and so on). This is my photo slideshow jquery code:

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 rndN开发者_Go百科um = 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>

My 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="newbox"><h4><a href="/href">WTF?!</a></h4><p>something</p><a class="bttn action" href="/shop/what-the-at-taz">Buy Now</a> <a class="bttn" href="/shop/explore?designer=211">See More</a></div>
    </div>


use $active.children('.newbox').text('write your text here');

0

精彩评论

暂无评论...
验证码 换一张
取 消