Event delegation and how to stopPropagation preventDefaults

Jorik Tangelder edited this page Sep 1, 2014 · 3 revisions

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.


Stops bubbling the gesture event to its parents. So you can create nested events.


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.


Stops the source event ev.gesture.srcEvent from bubbling. The source event could be touchstart, touchmove, mousemove etc.


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.


Stops Hammer from detecting any further gestures, in the current detection session. Might be usefull to call after you did a succesfull swipe.