Sha*_*ane 5 javascript mobile web
我试图完全消除移动浏览器中长按元素时发生的振动.
具体来说,我有一个图像,我正在添加我自己的长按功能,但默认发生的微妙的短振动是干扰,我需要禁用它.
我通过覆盖它成功地停止了通常的上下文菜单,如下所示:
window.oncontextmenu = function (event) {
event.preventDefault();
event.stopPropagation();
return false;
};
Run Code Online (Sandbox Code Playgroud)
我还添加了CSS来停止突出显示和文本选择等 - 但我几乎没有能够弄清楚几百毫秒后导致默认振动的原因.
是否有其他生命周期事件在oncontextmenu内部或周围的移动浏览器中长时间弹出?
完整的plunker示例在这里,从移动浏览器上长按图像(我在Android上使用chrome)看看我的意思:https://plnkr.co/edit/y1KVPltTzEhQeMWGMa1F?p = preview
单击时禁用文本选择。
document.querySelector("#your_target").addEventListener("touchstart", (e) =>
{
e.preventDefault();
e.stopPropagation();
this.style.userSelect = "none";
});
document.querySelector("#your_target").addEventListener("touchend", (e) =>
{
e.preventDefault();
e.stopPropagation();
this.style.userSelect = "default";
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
276 次 |
| 最近记录: |