javascript - The JQuery window object scroll top function -
javascript - The JQuery window object scroll top function -
i started learning javascript , jquery, , have question regarding window object $(window). have code, create div stick top of screen when scrolled top.
$(function () { $(window).scroll(function(){ var window_top = $(window).scrolltop(); var div_top = $("#sticky-anchor").offset().top; if (window_top > div_top) { $('#sticky').addclass('stick'); } else { $('#sticky').removeclass('stick'); } }); }); what don't understand if entire screen window, when window_top > div_top?
the top property returns topmost browser window of current window.
top useful both when you're dealing frames , when dealing windows have been opened other pages.
the place in reddish considered top! if scroll page, whichever part of page in red area, part @ window.top.
so, if div above top, window_top > div_top returns true otherwise else part gets executed!
javascript jquery
Comments
Post a Comment