0

I try to find the scroll position using mousewheel event like below:

container.on("mousewheel", function(e) {
  if(e.originalEvent.deltaY>0){
   //down
  }else{
   //up
  }
});

and my problem is when I scroll it down delta equals negative value at the end. Here is the screenshot of values:

enter image description here

I tried to compare old and new value of scroll top of element but got same result. Is there any different way of handling it?

P.S : The values that are shown are scrolled with touchpad, Device: Macbook Pro

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Jamil Alisgenderov
  • 1,448
  • 2
  • 12
  • 23
  • https://stackoverflow.com/questions/2481350/how-to-get-scrollbar-position-with-javascript check this ;) I think there is some much simpler approach. – sjahan Nov 09 '17 at 08:45
  • @sjahan - I am trying to find if it is moving up or down. – Jamil Alisgenderov Nov 09 '17 at 08:49
  • sorry I read it too fast! That's odd, i'm gonna check it, i've done it before on an old project. – sjahan Nov 09 '17 at 08:53
  • That's pretty weird, you definitely shouldn't get some negative values. Do you have some JS/native enhanced scrolling enabled? For example, on mobile devices, the scroll can bounce when it reaches the end of the scrollbar, maybe it could come from that? – sjahan Nov 09 '17 at 09:02
  • Yeah that's weird, but maybe it s related to the touchpad. I am scrolling with two finger gesture. But anyway I think it is problem. – Jamil Alisgenderov Nov 09 '17 at 09:06
  • This probably has something to do with overscrolling. With touchpad on Macs, and finger-scrolling on mobile devices, when the scrolling container reaches one end it overscrolls and then bounces back, hence negative deltas (or positive when scrolling up). You can deactivate overscrolling (in all major browsers, [except Safari](https://caniuse.com/css-overscroll-behavior)) with `overscroll-behavior: contain;`. – drinking-code Mar 27 '21 at 14:01

0 Answers0