ajax - twitter bootstrap dynamic carousel -
ajax - twitter bootstrap dynamic carousel -
i'd utilize bootstrap's carousel dynamically scroll through content (for example, search results). so, don't know how many pages of content there be, , don't want fetch subsequent page unless user clicks on next button.
i looked @ question: carousel dynamic content, don't think reply applies because appears suggest loading content (images in case) db server side , returns static content.
my best guess intercept click event on button press, create ajax phone call next page of search results, dynamically update page when ajax phone call returns, generate slide event carousel. none of discussed or documented on bootstrap pages. ideas welcome.
if (or else) still looking solution on this, share solution discovered loading content via ajax bootstrap carousel..
the solution turned out little tricky since there no way determine current slide of carousel. info attributes able handle .slid
event (as suggested) , load content url using jquery $.load()
..
$('#mycarousel').carousel({ interval:false // remove interval manual sliding }); // when carousel slides, load ajax content $('#mycarousel').on('slid', function (e) { // index of active item var idx = $('#mycarousel .item.active').index(); var url = $('.item.active').data('url'); // ajax load data-url $('.item').html("wait..."); $('.item').load(url,function(result){ $('#mycarousel').carousel(idx); }); }); // load first slide $('[data-slide-number=0]').load($('[data-slide-number=0]').data('url'),function(result){ $('#mycarousel').carousel(0); });
demo on bootply
ajax twitter-bootstrap carousel
Comments
Post a Comment