scrollto - jQuery Accordion - Scroll to element with specific class on section open -


i have combined search function jqueryui accordion.
search function highlights title of every section inputted search term found. trying figure out way have viewport scroll first occurrence of found term when section opened, saving user having scroll through potentially long content.
each highlighted term wrapped in <span class="highlight"&gt;term&lt;/span>. have got point i've added onclick="jumpto(chapter_number)" handler each section header when term found within it. need jumpto function. thank you!

here's fiddle: http://jsfiddle.net/jameshuckabonetech/ysddn/

p.s. fiddle great! first 1 ...

update finished working code ...

$( "#accordion" ).accordion( {     autoheight: false, collapsible: true, active: false,     activate:function(event, ui )     {         if ($(ui.newpanel).find('.highlight').length>0 && $("#jump-box").prop('checked') == true)             $('html, body').animate(             {                 scrolltop: $(ui.newpanel).find('.highlight').offset().top             }             , 2000);     } }); 

don't use onclick use accordion's activate event.

$( "#accordion" ).accordion({     autoheight: false, collapsible: true, active: false,     activate:function(event, ui ){        if ($(ui.newpanel).find('.highlight').length>0)           $('html, body').animate({               scrolltop: $(ui.newpanel).find('.highlight').offset().top               }, 2000);     },     beforeactivate:function(e,ui)     {         //if statement check if want stop accordion opening         e.preventdefault();     } }); 

used scrolling code jquery scroll element


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -