ben*_*ope 5 angularjs angularjs-ng-touch
角度触摸ngTouch会导致触摸释放时发生咔嗒声.
有没有办法让点击发生在触摸开始?
fast-click下面的指令似乎在触摸屏上做了我想要的,但它不适用于鼠标点击.
myApp.directive('fastClick', ['$parse', function ($parse) {
return function (scope, element, attr) {
var fn = $parse(attr['fastClick']);
var initX, initY, endX, endY;
var elem = element;
elem.bind('touchstart', function (event) {
event.preventDefault();
initX = endX = event.touches[0].clientX;
initY = endY = event.touches[0].clientY;
scope.$apply(function () { fn(scope, { $event: event }); });
});
};
}
]);
Run Code Online (Sandbox Code Playgroud)
tym*_*eJV 14
添加click到touchstart活动中 - event.preventDefault()将取消事件发生两次:
elem.bind('touchstart click', function (event) {
Run Code Online (Sandbox Code Playgroud)
我在一个应用程序中使用的快速快速代码是:
app.directive("ngMobileClick", [function () {
return function (scope, elem, attrs) {
elem.bind("touchstart click", function (e) {
e.preventDefault();
e.stopPropagation();
scope.$apply(attrs["ngMobileClick"]);
});
}
}])
Run Code Online (Sandbox Code Playgroud)
并使用如下: ng-mobile-click="myScopeFunction()"
| 归档时间: |
|
| 查看次数: |
9472 次 |
| 最近记录: |