javascript - How can I determine the direction of a jQuery scroll event? -
i'm looking effect:
$(window).scroll(function(event){ if (/* magic code*/ ){ // upscroll code } else { // downscroll code } });
any ideas?
check current scrolltop
vs previous scrolltop
var lastscrolltop = 0; $(window).scroll(function(event){ var st = $(this).scrolltop(); if (st > lastscrolltop){ // downscroll code } else { // upscroll code } lastscrolltop = st; });
Comments
Post a Comment