1

I have downloaded Hammers.js version-1.0.10 i have many try to call 'pinch in' function from js file but it can't execute. i think in library problem i have download other but same problem occurs.Other function like Touch,swipe, drag all works only pinch is not working[not calling]. If any one know than tell me.

Thank you

2 Answers 2

3

I'm not sure aout the specific version. In 2.0.2 pinch is disabled by default. Enable it using something like:

mc.get('pinch').set({enable: true})
1
  • Oh my god, I searched about 2 hours for this solution. Thank you! Where did you get this information?
    – dude
    Commented Nov 13, 2015 at 14:32
1

I've taken a closer look at that version now and events for "pinch", "pinchin", "pinchout" and "transform" should all be being fired.

If you don't have a minified version, you can see this at line 1217

inst.trigger('pinch', ev);
inst.trigger('pinch'+ ((ev.scale < 1) ? 'in' : 'out'), ev);

"transform" and "pinch" are the more general events. You can use the event data to determine whether or not it is in or out.

As I first suggested, you can use the "transform" event. The pinch zoom example that shipped with version 1.0.10 also used the transform event:

hammertime.on('touch drag transform', function(ev) {
    switch(ev.type) {
        case 'touch':
            last_scale = scale;
            last_rotation = rotation;
            break;

        case 'drag':
            posX = ev.gesture.deltaX;
            posY = ev.gesture.deltaY;
            break;

        case 'transform':
            rotation = last_rotation + ev.gesture.rotation;
            scale = Math.max(1, Math.min(last_scale * ev.gesture.scale, 10));
            break;
    }

    // transform!
    var transform =
            "translate3d("+posX+"px,"+posY+"px, 0) " +
            "scale3d("+scale+","+scale+", 0) " +
            "rotate("+rotation+"deg) ";

    rect.style.transform = transform;
    rect.style.oTransform = transform;
    rect.style.msTransform = transform;
    rect.style.mozTransform = transform;
    rect.style.webkitTransform = transform;
});

The firing of pinchin/out events is in a conditional for the transform_min_scale value being met. When you create your hammer elements, try setting transform_min_scale to something like -1.

4
  • Yep, Pinch not work but using Transform i have completed work Commented Aug 30, 2014 at 5:29
  • I'm glad you got it working, though I fear I haven't really answered your question. I've taken a closer look and I can't see a reason why looking at pinch events wouldn't work as well. If you go to github and find your release version, you'll find a pinch zoom example. This would have given you my solution in telling you to use the transform event, but as for why pinch doesn't work, I am at a loss.
    – Jools
    Commented Aug 30, 2014 at 23:47
  • Yes, I am also finding but i finding that we have to change in Hammer.js library for working pinch event. because in Library the pinch is not available it's available as form of transform. Commented Sep 1, 2014 at 4:59
  • Thanks for your source-code reference!! it helped me solve my problem.... I was trying to trigger something on pinchin assuming that meant the effect is what you get natively by "pinching in" , but it is the physical motion of one's fingers pinching together!
    – simey.me
    Commented Jun 14, 2017 at 2:31

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