Preferably using jquery. I found articles on a toaster, but I didn’t get a working version, I decided to ask more specifically here. $ (window) .scrollTop () - allows you to track how much scrolled down, but I do not understand how to use this function to find out if you are turning up or down.

I understand humanly that this should work like this:

  • If scrollTop ()> current position, then DOWN.
  • If scrollTop () is <current position, then UP.

It is not clear how to register the current position.

1 answer 1

var lastScrollTop = 0; $(window).scroll(function(event){ var st = $(this).scrollTop(); if (st > lastScrollTop){ // downscroll code } else { // upscroll code } lastScrollTop = st; }); 

or

 $(window).bind('mousewheel', function(event) { if (event.originalEvent.wheelDelta >= 0) { console.log('Scroll up'); } else { console.log('Scroll down'); } });