[英]AngularJS - How to not trigger hover action (ng-mouseenter) on mobile devices and only the cilck event
I'm using AngularJS, and I currently have both a hover behaviour (using ng-mouseenter and ng-mouseleave) so when you hover on my content elements, it shows content on the page, but if you click on that element (using ng-click) it should go into a detail page for that element. 我正在使用AngularJS,并且目前同时具有悬停行为(使用ng-mouseenter和ng-mouseleave),因此当您将鼠标悬停在我的内容元素上时,它会在页面上显示内容,但是如果您单击该元素(使用ng -click),它应该进入该元素的详细信息页面。
I have all of these configured on the same <div>
, and it works on desktop. 我将所有这些配置在相同的
<div>
,并且可以在桌面上使用。 But if I use my iPhone, then when I click the element, it triggers the hover action instead of the click action. 但是,如果我使用我的iPhone,则当我单击该元素时,它会触发悬停操作而不是单击操作。 It takes a second click to get to the click action, and I want it to trigger on the first click for mobile devices.
需要第二次单击才能执行单击操作,我希望它在移动设备的第一次单击时触发。
How can I achieve this? 我该如何实现?
Thanks for any help you can offer. 谢谢你的尽心帮助。
You should emulate double click on touch devices. 您应该模拟双击触摸设备。 You can use this directive:
您可以使用以下指令:
angular.module('app').directive('touchDevicesClick', function() {
return function(scope, elem) {
var element = angular.element(elem);
element.on('touchstart', function(e) {
element.triggerHandler('click')
});
};
})
or you can use $(elem).click()
instead element.triggerHandler('click')
或者您可以使用
$(elem).click()
代替element.triggerHandler('click')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.