Why doesn't click event always fire?

前端 未结 3 868
离开以前
离开以前 2021-02-11 16:17

If you\'re revisiting this question I\'ve moved all the updates to the bottom so it actually reads better as a question.

The Problem

I\'ve got a bit o

相关标签:
3条回答
  • 2021-02-11 17:15

    The problem could be with the rectangle layer too or with the way you call your event suppressor. It may simply cause your keyup event to hang instead of being cancelled so your first key up event returns after the second click. You should implement a counter on your events to verify this theory and return the value of the counter with the event name in the log.

    0 讨论(0)
  • 2021-02-11 17:21

    I recently came across this again, and fortunately have managed to isolate the problem and work around it.

    It was actually due to something being registered in the mousedown event, which was moving the DOM element svg:circle to the top based on a z-order. It does this by taking it out the DOM and re-inserting it at the appropriate place.

    This produces something that flows like this:

    • mouseenter
    • mousedown
      • (move DOM element but keep same event wrapper)
      • mouseup

    The problem is, as far as the browser is concerned the mousedown and mouseup occurred almost on different elements in the DOM, moving it has messed up the event model.

    Therefore in my case I've applied a fix by firing the click event manually on mouseup if the original mousedown occured within the same element.

    0 讨论(0)
  • 2021-02-11 17:23
    var events = function(g) {
    
        // Register the raw events required
        g.on("mousedown.test", mousedown)
         .on("mouseenter.test", mouseenter)
         .on("mouseleave.test", mouseleave)
         .on("click.test", clicked)
         .on("contextmenu.test", contextMenu)
         .on("dblclick.test", doubleClicked);
    
        return g;
    };
    

    Returning g instead of events might resolve the problem.

    0 讨论(0)
提交回复
热议问题