jquery mobile - silentScroll() to specific item within collapsible set -


i'm creating jquery mobile app glossary. time user touches term in glossary want open glossary, open collapsible id, , scroll it.

// links within element, assign click handler var links = element.find(".glossarylink"); links.each(function(index){     $(this).on("click", function(){         var regex = /\w/g;         var searchid = this.innerhtml.replace(regex, "").tolowercase();         // open glossary         window.location = "#glossary";         var entry = $("#" + searchid);         // working fine, correct collapsible opening         entry.collapsible( "option", "collapsed", false );          // returns 0...         var pos = entry.offset().top;         // ...meaning nothing         $.mobile.silentscroll(pos);     } }); 

the code seems working ok in can open correct collapsible (i'm getting correct <div> within collapsible-set) value of pos 0, doesn't scroll.

the jquery api offset() says doesn't support hidden elements this post seems suggest auto-scrolling possible on collapsible.

any appreciated!

edit

as i've said in comments below, settimeout() trick isn't working if time < 500ms. using @omar ingenious solution of assigning listener kicking off works...

function addglossaryclickhandlers(element){     var links = element.find(".glossarylink");     links.each(function(index){         $(this).on("click", function(){             var regex = /\w/g;             var searchid = this.innerhtml.replace(regex, "").tolowercase();             window.location = "#glossary";             var entry = $("#" + searchid);             // assign listener kick off expanding collapsible             entry.on("collapsibleexpand", function(){                 var pos = entry.offset().top;                 $.mobile.silentscroll(pos);             }).collapsible("expand");         });     }); } 

...but pos above again returning 0. stumped again, can help? stripped down jsfiddle although reason last link in collapsible broken...

you'll want move logic calculates offset , silentscroll settimeout.

as comment: typically, settimeout(func, 0) norm. however, html5 spec states 4ms, you'll see code samples settimeout(func, 4) used.

if you're interested why works, here's great break down what's happening , why settimeout addresses issue (it's due events):

https://stackoverflow.com/a/4575011/1253479

thanks!


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -