Mouseleave triggered by click

前端 未结 6 1547
囚心锁ツ
囚心锁ツ 2021-01-01 11:38

I have an absolutely-positioned div, and I\'m trying to keep track of when the mouse moves over it, and when the mouse leaves. Unfortunately clicking on the text in the box

6条回答
  •  悲&欢浪女
    2021-01-01 11:59

    I also ran into this bug. In my case, I added label wrapped checkboxes into a list, and wrapped the list in a div. I also used some list items that were


    tags. If you click around the checkboxes and labels quickly you will occasionally trigger a mouseleave event on the wrapping div. This shouldn't occur as all clicked elements are children of the div.wrapper.

    ...
      wrapper.addEventListener(
        'mouseleave',
        (e) => {
          logger('mouseleave fired');
          console.log('mouseleave fired', e);
        },
        false
      );
    ...
    

    jsfiddle demo

    Here's a gif of the reproduction. Click within the clue area (granted with some intensity and movement), click events from the label and input boxes are firing and then you see two mouseleave events fire in error, and then a third when the mouse truly leaves the blue area.

提交回复
热议问题