我有一个非常具体的问题。我正在为移动手机编写网页,其中有一个按钮。我在所有浏览器(包括IE)上检测到 touchevent
,但在IE上它很特殊。几秒钟后它会自动结束。你能帮我吗?这是我的代码(修改过的,但仍然没有正常工作):
if (window.navigator.pointerEnabled) {
tapButton.addEventListener("pointerup", function(e) {
e.preventDefault();
addClass(this, 'clicked');
buttonTouched = true;
}, false);
tapButton.addEventListener("pointerdown", function(e) {
e.preventDefault();
removeClass(this, 'clicked');
buttonTouched = false;
}, false);
alert("pointerEnabled");
}
else if (window.navigator.msPointerEnabled) {
tapButton.addEventListener("MSPointerDown", function(e) {
e.preventDefault();
addClass(this, 'clicked');
buttonTouched = true;
}, false);
tapButton.addEventListener("MSPointerUp", function(e) {
e.preventDefault();
removeClass(this, 'clicked');
buttonTouched = false;
}, false);
alert("mspointerEnabled");
}
else {
alert("ordinary touch");
tapButton.addEventListener('touchstart', function(e) {
e.preventDefault();
addClass(this, 'clicked');
buttonTouched = true;
}, false);
tapButton.addEventListener('touchend', function(e) {
e.preventDefault();
removeClass(this, 'clicked');
buttonTouched = false;
}, false);
}
而 HTML 标签中包含了:
-ms-touch-action: none !important;
touch-action: none !important;
但那也没有任何帮助。
window.ondevicemotion
。从在Chrome中打开的页面连接电话会给我带来同样的消息,但是当我倾斜手机时啤酒杯正在移动(在IE中不是)。 - Cliff Burton