Prevent click event from firing when dblclick event fires

前端 未结 12 1310
名媛妹妹
名媛妹妹 2020-12-02 20:17

I\'m handling both the click and dblclick event on a DOM element. Each one carries out a different command, but I find that when double clicking on the element, in addition

12条回答
  •  猫巷女王i
    2020-12-02 21:03

    In a comment, you said,

    I delay the click handler by 300 ms (a noticeable and annoying delay) and even ...

    So it sounds like what you want is that when you click then the DOM should geneate a click event immediately, except not if the click is the first click of a double-click.

    To implement this feature, when you click, the DOM would need to be able to predict whether this is the final click or whether it's the first of a double-click (however I don't think is possible in general for the DOM to predict whether the user is about to click again).


    What are the two distinct actions which you're trying to take on click and double-click? IMO, in a normal application you might want both events: e.g. single-click to focus on an element and then double-click to activate it.

    When you must separate the events, some applications use something other than double-click: for example, they use right-click, or control-click.

提交回复
热议问题