嗨,我有跟随div:
angular.module("myApp", ['ngTouch']).controller("myController", function($scope) {
$scope.longClick = function() {
console.log('I was clicked long');
}
});
.longClick {
width: 200px;
height: 20px;
line-height: 20px;
color: white;
font-family: Arial;
background-color: grey;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-touch.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" class="longClick" ng-click="longClick()">Click me long...</div>
我想在平板电脑上检测到长按单击/触摸div并打印控制台中的文本。我找到了这些问题的答案,但我尝试的一切都没有用。有任何想法吗?感谢。
答案 0 :(得分:1)
我给你写了这段代码,它应该可以解决问题。 我基本上花了mousedown和mouseup的时间来比较它们
value
var start;
$(window).mousedown(function(e) {
start = new Date().getTime();
}).mouseup(function(e) {
var end = new Date().getTime();
var timeDiff = (end-start)/1000;
$('p').text(timeDiff + " seconds");
});