javascript - Dynamically change content on rcarousel -
i using "rcarousel – continuous jquery ui carousel" located @ http://ryrych.github.io/rcarousel/. after creating carousel, wish change content on 1 of carousel panes. change content enough following script: $('#carousel').find('input.change').click(function(){$(this).parent().parent().find('div.display').html('new content');});
problem if go pane, back, "changed" pane reverts it's original content.
a live example located @ http://tapmeister.com/test/ryrych-rcarousel/examples/dynamic.php, , script included below.
var active=true; $("#carousel").rcarousel( { visible: 1, step: 1, width: 780, height: 240, speed: 500, startatpage: 2, start: function() { var carousel=$(this),parent=carousel.parent(); $('#next-slide').click(function(){if(active) {carousel.rcarousel("next");}}); $('#prev-slide').click(function(){if(active) {carousel.rcarousel("prev");}}); ( var = 0; < carousel.rcarousel( "gettotalpages" ); i++ ) { $("<a />",{href:'#','class':'carousel-bullet off'}) .bind("click", {page: i}, function( event ) { if(active) { carousel.rcarousel( "gotopage", event.data.page ); event.preventdefault(); } } ) .appendto( "#carousel-pages" ); } // mark first page active $( "a:eq(0)", "#carousel-pages" ) .removeclass( "off" ) .addclass( "on" ) .css("background-image", "url(images/page-on.png)" ); $("#next-slide, #prev-slide, .carousel-bullet" ) .hover( function(){ if(active){$( ).css("opacity", 0.7 );} }, function(){ if(active){$( ).css("opacity", 1.0 );} } ); }, pageloaded: function( event, data ) { $( "a.on", "#carousel-pages" ) .removeclass( "on" ) .css("background-image", "url(images/page-off.png)" ); $( "a", "#carousel-pages" ) .eq( data.page ) .addclass( "on" ) .css("background-image", "url(images/page-on.png)" ); } } ); <div id="carousel-container"> <div id="carousel"> <div class="slide"> <div class="sub-slide"> <img src="images/throbber.gif" class="throbber" alt="please wait" /> <div class="display">display 0</div> </div> <div class="buttons"> <input class="change" type="button" value="change"> </div> </div> <div class="slide"> <div class="sub-slide"> <img src="images/throbber.gif" class="throbber" alt="please wait" /> <div class="display">display 1</div> </div> <div class="buttons"> <input class="change" type="button" value="change"> </div> </div> <div class="slide"> <div class="sub-slide"> <img src="images/throbber.gif" class="throbber" alt="please wait" /> <div class="display">display 2</div> </div> <div class="buttons"> <input class="change" type="button" value="change"> </div> </div> <div class="slide"> <div class="sub-slide"> <img src="images/throbber.gif" class="throbber" alt="please wait" /> <div class="display">display 3</div> </div> <div class="buttons"> <input class="change" type="button" value="change"> </div> </div> <div class="slide"> <div class="sub-slide"> <img src="images/throbber.gif" class="throbber" alt="please wait" /> <div class="display">display 4</div> </div> <div class="buttons"> <input class="change" type="button" value="change"> </div> </div> <div class="slide"> <div class="sub-slide"> <img src="images/throbber.gif" class="throbber" alt="please wait" /> <div class="display">display 5</div> </div> <div class="buttons"> <input class="change" type="button" value="change"> </div> </div> </div> <a href="#" id="next-slide" class="change-slide"></a> <a href="#" id="prev-slide" class="change-slide"></a> <div id="carousel-pages"></div> </div>
add following updatepagedom()
method plugin
updatepagedom: function() { var $root = $(this.element), data=$root.data("data"); //note data.paths[data.pageindex] , data.pages[data.pageindex][0] same data.paths[data.pageindex].html($root.find('div.slide').html()); },
Comments
Post a Comment