简体   繁体   中英

How to determine if event was fired from scrollbar

I have a div in which I have implemented iPad like swiping.

Check out what I mean on JSFiddle (Just click and drag your mouse in the div.)

I want to prevent the swiping from happening when someone is using the scroll bar (click on the scrollbar, then move from left to right, swiping still occurs).

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

jQuery and regular 'ol Javascript answers welcomed.

Edited: To make a lot more sense.

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

Step 1: Capture the MouseDown event. Store the current position of scrollLeft and scrollTop into variables.

Step 2: On the MouseMove event, check the current position of scrollLeft and scrollTop and compare them against your variables. If they're different, then cancel whatever operation you were going to perform. If they're the same, the MouseDown event wasn't triggered by a scrollbar (or anything else that would change scrollLeft and scrollTop such as another animation), and you're free to do what you wish!

Happy coding!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM