javascript - Detect if page is scrolled on document load -
i'm using scrolltop
detect if users scrolls fadein
element:
$(document).ready(function() { // scroll top $(window).scroll(function() { if ($(this).scrolltop() >= 700) { // if page scrolled more 700px $('#return-to-top').fadein(200); } else { $('#return-to-top').fadeout(200); } }); });
it works if user loads page , scroll, if user below 700px , reload or goes same page element doesn't fadein
automatically on document load. seems not detecting page scrolled.
any idea problem code?
just test when document ready
it's better create function
function checkscroll(){ if ($(window).scrolltop() >= 700) { $('#return-to-top').fadein(200); } else { $('#return-to-top').fadeout(200); } } $(document).ready(function() { checkscroll(); $(window).scroll(checkscroll); });
Comments
Post a Comment