Skip to content

Getting Started

jtangelder edited this page Feb 27, 2013 · 23 revisions

Hammer became simpler to use, with an jQuery-like API. You don't need to add the new keyword, and the eventlisteners are chainable.

    var element = document.getElementById('test_el');
    var hammertime = Hammer(element).on("tap", function(event) {
        alert('hello!');
    });

You can change the default settings by adding an second argument with options

    var hammertime = Hammer(element, {
        drag: false,
        transform: false
    });

Events can be added/removed with the on and off methods, just like you would in jQuery. Event delegation is also possible when you use the jQuery plugin.

    $('#test_el').hammer().on("tap", ".nested_el", function(event) {
        console.log(this, event);
    });
Clone this wiki locally