jquery - Getting the current scroll position in Chrome using scrollTop() on page load/refresh -


running following in chrome returns 0:

$(window).on('load', function(){      console.log($(window).scrolltop()); }); 

running same command via console:

$(window).scrolltop() 

does return correct number. (i.e.: 843)

there lot of questions issue here on stackoverflow none of them have given me correct working answer or alternative. i'm @ loss...

the scrolltop() returns current vertical position of scroll bar. typically on page load, scroll bar @ position 0. if console prints out else, or browser must have scrolled down before function called.

if using named anchors or refreshing page scrolled position, can bind handler scroll event triggers once - on page load:

$(window).on('scroll', function() {     console.log( $(this).scrolltop() ); }); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -