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

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

问题描述

我的问题是我无法取消触发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();
}

请有人告诉我如何取消在手指触摸屏幕触发touchstart事件后触发的mousedown事件.

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
}); 

请注意,在这种情况下,click是变量,而不是字符串.

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

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

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