1

I want to capture pinch events on an image in a webpage using hammer.js (or anything else is also fine). I've got two implementations of which neither works as expected. I'm testing with Android 4.1 and chrome, but would like it to be a cross browser solution (ha! if that exists...)

The first doesn't fire the pinch events at all. http://jsfiddle.net/7EV56/9/

$elem.hammer()
    .on("pinchin", function (evt)
    {
        //do stuff
    }).on("pinchout", function (evt)
    {
        //do stuff
    });

The second fires the pinch events perfectly, but then I can't pan/scroll anymore. http://jsfiddle.net/7EV56/8/

$elem.hammer({prevent_default:true})
    .on("pinchin", function (evt)
    {
        //do stuff
    }).on("pinchout", function (evt)
    {
        //do stuff
    }); 

1 Answer 1

4

Out of desperation I tried every available option in the initialisation argument and lo and behold:

transform_always_block: true

Not sure what the effect is of doing this. Hopefully it won't break several other pieces of functionality, but at least these two are now fixed.

It would be very much appreciated if anyone can still shed some light on what this actually does and why it fixed it.

Cheers

3
  • In the source (github.com/EightMedia/hammer.js/blob/master/src/gestures/…) for transform.js (i.e. this gesture's source within hammer.js) a comment for this property says: "prevent default browser behavior when two touches are on the screen but it makes the element a blocking element when you are using the transform gesture, it is a good practice to set this true" - hope that clears it up for you!
    – Coder
    Commented Mar 18, 2014 at 17:52
  • @Coder Thanks, but I saw that comment in the docs and don't really know what it's talking about. Probably due to my general lack of understanding of this stuff though. I mean, what is the 'default browser behaviour' and what is a 'blocking element' Commented Mar 18, 2014 at 21:20
  • 1
    Well at a guess this option stops the browser from handling these events as well as your handler, i.e. your element "blocks" any propogation of the event. I agree it's not obvious though. Your solution was what I needed to do and finding your answer solved my problem! :)
    – Coder
    Commented Mar 19, 2014 at 16:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.