javascript - Firefox scrollTop problem -
i have problem firefox scrolltop value , onscroll event. works great in ie, safari , chrome firefox seems lag.
i tried update background position onscroll event, when take handle , drag , down quickly, firefox stops updating scrolltop value , causes lag in app.
you can try code , in firefox console when dragging handle , see values stops updating :
function savescrolllocation () { console.log(document.documentelement.scrolltop); } window.onscroll=savescrolllocation ;
any idea how make firefox respond more quickly?
there 2 ways handle - throttle (execute function set interval) , debounce (execute function after specified time has passed since last call). you'll want use throttling in situation.
a simplified solution may (updated: see @ http://jsfiddle.net/yvvnu/1/):
window.onscroll=catchscroll; var timeoutid = 0; var jitterbuffer = 200; function catchscroll() { if (timeoutid) cleartimeout (timeoutid); timeoutid = settimeout(function(){savescrolllocation()}, jitterbuffer); } function savescrolllocation () { console.log(document.documentelement.scrolltop); alert('scrolled'); }
you can use jquery plugin: http://benalman.com/projects/jquery-throttle-debounce-plugin/
Comments
Post a Comment