最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect when touch event is over in Hammer.js and jQuery - Stack Overflow

programmeradmin0浏览0评论

In Hammer.js 2.02, how do you detect when a press gesture has ended?

I have a 'press' recognizer on an element with a time of 1 which prints a message as soon as the press event starts. But how do I check when the user has lifted their finger? Right now I'm using the 'pressup' recognizer which nearly works, except that it only triggers if the user has held their finger down for >500ms. How can I check when shorter presses end?

var pressOptions = {
    event: 'press',
    pointer: 1,
    threshold: 5,
    time: 1
};

var trackpadRight = $('#trackpad-right').hammer();
trackpadRight.data("hammer").get('press').set(pressOptions);

trackpadRight.bind('press', function(ev) {
    console.log("PRESSS DOWN");
});

trackpadRight.bind('pressup', function(ev) {
    console.log("PRESS UP");
});

In Hammer.js 2.02, how do you detect when a press gesture has ended?

I have a 'press' recognizer on an element with a time of 1 which prints a message as soon as the press event starts. But how do I check when the user has lifted their finger? Right now I'm using the 'pressup' recognizer which nearly works, except that it only triggers if the user has held their finger down for >500ms. How can I check when shorter presses end?

var pressOptions = {
    event: 'press',
    pointer: 1,
    threshold: 5,
    time: 1
};

var trackpadRight = $('#trackpad-right').hammer();
trackpadRight.data("hammer").get('press').set(pressOptions);

trackpadRight.bind('press', function(ev) {
    console.log("PRESSS DOWN");
});

trackpadRight.bind('pressup', function(ev) {
    console.log("PRESS UP");
});
Share Improve this question asked Aug 5, 2014 at 18:43 user2693059user2693059 452 silver badges6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Just use Hammer without jQuery.

var pressOptions = {
    // event: 'press', //no need to pass defaults
    // pointer: 1,
    // threshold: 5,
    time: 1
};

var trackpadRightTouch = new Hammer(document.getElementById('trackpad-right'));
trackpadRightTouch.get('press').set(pressOptions);

trackpadRightTouch.on('press', function(ev) {
    console.log("PRESSS DOWN");
});

trackpadRightTouch.on('pressup', function(ev) {
    console.log("PRESS UP");
});

this should work.

From your ment, I thought you need to detect the touch release. If yes then you can use the default "touchend" event by directly bind to the element, like below:

$('#trackpad-right').bind('touchend', function(ev) {
    console.log("PRESS UP");
});
发布评论

评论列表(0)

  1. 暂无评论