簡體   English   中英

在IE11中使用指針事件時阻止單擊?

[英]Prevent click when using pointer events in IE11?

我正在開發一個必須在IE11和Edge上運行的JavaScript應用程序。 在IE11中,我看到的事件鏈(從https://patrickhlauke.github.io/touch/tests/results/復制)如下:

指針> mouseover> pointerenter> mouseenter> pointerdown> mousedown>(pointermove> mousemove)+> pointerup> mouseup>(lostpointercapture)> pointerout> mouseout> pointerleave> mouseleave> focus> click

該應用程序已經連線處理鼠標和觸摸事件,所以我在所有指針事件上調用preventDefault()來取消相應的鼠標事件。 不幸的是,點擊在結束時出現並導致問題。 有沒有內置的方法來禁止點擊事件在最后解雇?

我正在使用jQuery指針事件Polyfill( https://github.com/jquery/PEP )在Webkit瀏覽器上使用“pointerup”事件,我遇到了類似的問題。 就我而言,我不得不阻止鏈接被跟蹤。

我通過在“pointerup”觸發后立即添加“click”事件偵聽器來解決問題,然后阻止“click”事件並刪除其偵聽器。 像這樣:

var myLink = document.getElementsByClassName("myLink")[0];

myLink.addEventListener("pointerup", handleLinkPress);

function handleLinkPress(evt) {
    // do something here...

    evt.target.addEventListener("click", unfollowLink);

    function unfollowLink(evt) {
        evt.preventDefault();
        evt.target.removeEventListener("click", unfollowLink);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM