-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Event delegation and how to stopPropagation preventDefaults
This WIKI is for the 1.1 version. For the 2.0 documentation, go to the website.
Hammer supports event delegation. It makes use of the createEvent method in JS, to create DOM events. When you take a look at the event object of a gesture event, you will see some methods, which might be confusing.
ev.stopPropagation()
Stops bubbling the gesture event to its parents. So you can create nested events.
ev.preventDefault()
Prevents the browser from doing it's native gesture implementation. It doesn't make any sense, only for the drag events, since most browsers support dragstart-drag-dragend. It is in Hammer, because document.createEvent
adds these, and Hammer uses this for creating DOM events.
ev.gesture.stopPropagation()
Stops the source event ev.gesture.srcEvent
from bubbling. The source event could be touchstart, touchmove, mousemove etc.
ev.gesture.preventDefault()
Prevents the source event ev.gesture.srcEvent
from doing it's native behavior.when you use this, you can make the element blocking, because touchstart-touchmove let the browser scroll when you dont prevent the default action. This could be called when you are using the drag and transform events, but hammer does this for you in most cases.
ev.gesture.stopDetect()
Stops Hammer from detecting any further gestures, in the current detection session. Might be usefull to call after you did a succesfull swipe.