jQuery.on" touchstart mousedown" - 两个事件都在触摸屏设备上触发 [英] jQuery.on "touchstart mousedown" - both events are triggered on touchscreen device

查看:1376
本文介绍了jQuery.on" touchstart mousedown" - 两个事件都在触摸屏设备上触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我无法取消触发touchstart后触发的mousedown事件。此问题特定于Android的原生浏览器。

My problem is I cannot cancel the mousedown event that's fired after touchstart has been triggered. This problem is specific to Android's native browser.

Chrome和Safari都在Android和iOS(onMenuInteraction)中成功执行下面的方法。我的问题似乎仅限于Android的原生浏览器(对于我预装的Android 4.1.2)。

Chrome and Safari both successfully execute my method below in both Android and iOS (onMenuInteraction). My problem seems to be confined to Android's native browser (for me that's preinstalled with Android 4.1.2).

以下是我从Javascript对象中提取的代码

The following is code that I've extracted from my Javascript object.

MenuButtonView.prototype.onSmallScreenSetUp = function() {
    $("#mobileMenuBtn").on( { "touchstart mousedown": $.proxy( this.onMenuInteraction, this ) } );
}

MenuButtonView.prototype.onMenuInteraction = function(e) {
    console.log( this, "onMenuInteraction", e );
    e.stopImmediatePropagation();
    e.stopPropagation();
    e.preventDefault();
}

有人可以告诉我如何取消你之后被解雇的mousedown事件手指触摸屏幕触发touchstart事件。

Please could someone tell me how I can cancel the mousedown event that's fired after your finger touches the screen triggering the touchstart event.

此要求基于管理与桌面和移动/平板电脑平台的交互。一切正常,直到您使用Android原生浏览器进行测试。

This requirement is based on managing interaction with both desktop and mobile / tablet platforms. Everything works until you're testing with the Android native browser.

非常感谢

D

推荐答案

检查是否存在 touchstart 支持,设置变量以确定您提供的支持:

check for presence of touchstart support, set a variable to determine what support you provide:

//touchstart or mousedown
var click = ('ontouchstart' in document.documentElement)  ? 'touchstart' : 'mousedown';

然后使用:

$(element).on(click,function(){
    //do stuff
}); 

请注意,此实例中的点击是一个变量,而不是字符串。

note that click in this instance is a variable, not a string.

这篇关于jQuery.on" touchstart mousedown" - 两个事件都在触摸屏设备上触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆