Gunjan Patel
Gunjan Patel

Reputation: 2372

Pinchin doesn't calll using Hammer library

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

Upvotes: 1

Views: 1170

Answers (2)

Jools
Jools

Reputation: 869

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.

Upvotes: 1

nlyk
nlyk

Reputation: 331

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})

Upvotes: 3

Related Questions