html - detect (event) attempting to scroll up/down when already at top/bottom of the page with javascript or angularJS, -


so want detect scrolling top(or bottom) when i'm @ top(or bottom) of page. i've seen couple questions similar problems here, answer detect mousewheel event.

but considering fact want detect when it's triggered similar action (like pressing up/down key, or mousewheel , touchpad scrolling, or pageup/down, or home/end ...) should create eventlisteners each , every 1 of them? know better way of doing it??

this have far. can detect when hit top or bottom regardless of how scrolled. issue detecting when trying keep scrolling after reached because scroll event not fire unless scroll. thing can think of programmatically scroll screen can scroll again, don't recommend doing that. other don't see other way other creating custom events each possible way user can scroll.

$(function(){ var lastscrollbarpos = 0; $(window).scroll(function(event){    var browserviewportheight = $(window).height();     var hmtldocheight = $(document).height();    var scrollbarpos = $(window).scrolltop();      if (scrollbarpos > lastscrollbarpos){        // downscroll code        console.log('scroll down');        if(hmtldocheight == browserviewportheight + scrollbarpos){          console.log('reached bottom');        }    } else {       // upscroll code       console.log('scroll up');          if(scrollbarpos == 0){           //we @ top , scrolling           console.log('reached top');       }    }    lastscrollbarpos = scrollbarpos; }); }); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -