我希望能夠捕捉到用戶通過觸摸設備上的一組DOM元素移動手指的事實。此示例在桌面瀏覽器上正常工作,但在移動Safari中查看時不會觸發所有預期的事件。如何使用角度指令捕獲觸摸事件
工作Plunkr(展示在移動Safari中的問題): http://plnkr.co/edit/J8sfuJ9o6DorMSFlK9v2
HTML:
<body ng-controller="MainCtrl">
<p>Hello {{name}}! This works from a desktop browser but not from mobile Safari. I would simply like to be able to drag my finger down, across all four letters, and have their events fire. I thought that touchMove would work in place of mouseMove when running this Plunkr on iOS, but it doesn't.</p> Current letter: {{currentLetter}}
<div swipe-over="swipeOver()">A</div>
<div swipe-over="swipeOver()">B</div>
<div swipe-over="swipeOver()">C</div>
<div swipe-over="swipeOver()">D</div>
</body>
的Javascript:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $log) {
$scope.name = 'World';
$scope.currentLetter = "";
$scope.swipeOver = function() {
$log.info("In swipeOver");
};
});
app.directive('swipeOver', function($log) {
return {
restrict: "A",
scope: true,
link: function(scope, element, attrs) {
// For touch devices
element.bind("touchmove", function() {
scope.$apply(function(evt) {
$log.info("in touchmove - " + element.text());
scope.$parent.currentLetter = element.text();
});
});
// For desktops
element.bind("mousemove", function(evt, e2) {
scope.$apply(function() {
$log.info(evt);
$log.info(e2);
$log.info("in mousemove - " + element.text());
scope.$parent.currentLetter = element.text();
});
});
}
};
});
我已經嘗試了NG-觸摸庫,但它確實不支持垂直觸摸動作,令人驚訝。在這一點上,任何幫助都會受到大力讚賞。 。 。
它可能與這個問題有關:[iphones-safari-touchmove-event-not-working] [1]? [1]:http://stackoverflow.com/questions/3531997/iphones-safari-touchmove-event-not-working –
您好, 我遇到同樣的問題。 你能告訴我你是如何解決它? –