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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -