是否可以防止使用JavaScript的触摸屏显示器,平板电脑,手机上的触摸手势?
最佳答案
您可以通过防止touchstart
事件来做到这一点。如果要在整个页面上进行操作,则可能要在身体上进行操作。
var body = document.body;
element.ontouchstart = function(e) {
e.preventDefault();
}
您也可以将
window.addEventListener
用于整个页面。window.addEventListener('touchstart', function(e) {
e.preventDefault();
}
这也将允许其他人加入
touchstart
事件。jQuery的
也可以通过
on
方法使用jQuery。$('body').on('touchstart', function(e) {
e.preventDefault();
});