How to determine if an event was fired from the scrollbar

I have a div in which I implemented the iPad as a scroll.

See what I mean JSFiddle (just click and drag in the div).

I want to prevent scrolling when someone uses a scroll bar (click on the scroll bar, then drag from left to right, it still scrolls).

In short, I need if (! Event.wasTriggeredFromScrollbar), which I can use in any event trigger (in this case mousedown / move / up).

jQuery and regular Javascript welcome responses are welcome.

Edited: To make a lot more sense.

+6
source share
1 answer

Here's how I got around this, as it doesn't seem possible.

Step 1: Capture the MouseDown Event. Save the current position of scrollLeft and scrollTop in variables.

Step 2: In the MouseMove event, check the current position of scrollLeft and scrollTop and compare them with your variables. If they are different, cancel any operation you are about to perform. If they match, the MouseDown event did not fire using the scrollbar (or anything else that could change scrollLeft and scrollTop, for example, another animation), and you can do whatever you want!

Happy coding!

+4
source

Source: https://habr.com/ru/post/899366/


All Articles