我正在尝试在触摸设备上分配一个手势来“删除照片”,双击是有意义的。是否有 Angular 友好的方法来检测 double-tap
,甚至是来自 javascript 的 long-tap
? Angular-touch 不支持开箱即用。
PS:我知道我可以使用 hammer.js,但如果可以避免,我宁愿不加载另一个库。 angular-carousel 已经加载了 angular-touch
最佳答案
我浏览了 angular-touch.js 并添加了这个:
longtapHandler = $parse(attr.ngLongtap),
这个:
/*
* add longtap event
*/
if (tapping && diff > (1 * TAP_DURATION) && dist < MOVE_TOLERANCE) {
// Call preventGhostClick so the clickbuster will catch the corresponding click.
preventGhostClick(x, y);
// Blur the focused element (the button, probably) before firing the callback.
// This doesn't work perfectly on Android Chrome, but seems to work elsewhere.
// I couldn't get anything to work reliably on Android Chrome.
if (tapElement) {
tapElement.blur();
}
if (!angular.isDefined(attr.disabled) || attr.disabled === false) {
element.triggerHandler('longtap', [event]);
}
}
还有这个
element.on('longtap', function(event, touchend) {
scope.$apply(function() {
longtapHandler(scope, {$event: (touchend || event)});
});
});
它似乎工作正常。
关于javascript - 你能从安装了angular-touch的javascript中检测到双击吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22257419/