Why can't I reliably capture a mouseout event?

后端 未结 6 1110
日久生厌
日久生厌 2020-11-30 00:18

I need to know when the mouse cursor leaves a div. So I hook up the mouseout event. However, if I move the mouse very quickly out of the div<

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 00:56

    I ran into this problem a few times and I came to accept the issue as a fact of life. But depend on your needs, you can just use CSS as I did. For example, if I just want to show/hide an element base on another element got hovered, then CSS is the way to go. Here is a working, reliable example:

    .large {
      width: 175px; height: 175px;
      position: absolute;
      border-radius: 100%;
    
      /*hide the glass by default*/
      top: -9999px;
      left: -9999px;
      opacity: 0;
      transition: opacity .2s ease-in-out;
      z-index: 100;
      pointer-events: none;
    }
    
    .small:hover + .large {
      opacity: 1;
    }
    

    http://codepen.io/tanduong/pen/aBMxyd

提交回复
热议问题