javascript - Equivalent of "hold" and "release" in hammer.js 2.0 - Stack Overflow

In hammer.js 1.1.3 version I was able to use the following code perfectly:var button = Hammer(element,

In hammer.js 1.1.3 version I was able to use the following code perfectly:

        var button = Hammer(element, {
            hold: true,
            release: true
        });

        button .on('hold', function() {
            //Do something when the hold event starts
        });

        button .on('release', function() {
            //Do something when the hold event stops
        });

But in hammer.js 2.0 I'm struggling to find an equivalent:

    var button = new Hammer.Manager(element);

    button.add(new Hammer.Press({
        event: 'press',
        pointer: 1,
        threshold: 5,
        time: 500
    }));

    button.on('press', function(event) {
        //Do something when the the element is pressed after 500ms
    });

    //Possible handler when the element is released?

According to the documentation (.html) for the new hammer.js 2.0, there are 5 recognizers:

    Pan, Pinch, Press, Rotate, Swipe, Tap

I couldn't find a appropriate recognizer that would allow release type functionality. Any thoughts, suggestions or ideas are appreciated. Cheers for reading!

In hammer.js 1.1.3 version I was able to use the following code perfectly:

        var button = Hammer(element, {
            hold: true,
            release: true
        });

        button .on('hold', function() {
            //Do something when the hold event starts
        });

        button .on('release', function() {
            //Do something when the hold event stops
        });

But in hammer.js 2.0 I'm struggling to find an equivalent:

    var button = new Hammer.Manager(element);

    button.add(new Hammer.Press({
        event: 'press',
        pointer: 1,
        threshold: 5,
        time: 500
    }));

    button.on('press', function(event) {
        //Do something when the the element is pressed after 500ms
    });

    //Possible handler when the element is released?

According to the documentation (http://hammerjs.github.io/getting-started.html) for the new hammer.js 2.0, there are 5 recognizers:

    Pan, Pinch, Press, Rotate, Swipe, Tap

I couldn't find a appropriate recognizer that would allow release type functionality. Any thoughts, suggestions or ideas are appreciated. Cheers for reading!

Share Improve this question edited Jul 14, 2014 at 9:33 JJJ 33.2k20 gold badges94 silver badges103 bronze badges asked Jul 12, 2014 at 12:16 Mr. SmithMr. Smith 5,55811 gold badges45 silver badges60 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

This will be supported in the next release, 2.0.1! https://github./hammerjs/hammer.js/mit/a764fde2e89c3af2575ae02d3af41d7787a60dc5

Managed to achieve this functionality using 'press' (hold) and 'pressup' (release)

var hammer = new Hammer(this);

hammer.on("press pressup", function (ev) {

    // Hold gesture start (press)
    if (ev.type == "press") {
        console.log("Hold active");
    }

    // Hold gesture stop (pressup)
    if (ev.type == "pressup") {
        console.log("Hold inactive");
    }
});

Tested on Hammer.JS v2.0.8

Using

$(button).on('touchend',function(e){});

Works on jQuery.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742329440a4423413.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信