mouseover function occurring multiple times in a queue

前端 未结 2 508
我寻月下人不归
我寻月下人不归 2021-01-25 15:03

I have this code that fades a div over another one upon mouseover, and fades out when the cursor leave the viewing area.

EXAMPLE: http://jsfiddle.net/3vgbemgu/



        
2条回答
  •  日久生厌
    2021-01-25 15:22

    You can use jquery .stop():

    $('.under').hover(function() {
      $('.over').stop(true, true).fadeIn();
    }, function() {
      $('.over').stop(true, true).fadeOut();
    });
    .frame {
      position: absolute;
      width: 400px;
      height: 300px;
    }
    .under {
      width: 100%;
      height: 100%;
      z-index: 1;
    }
    .under img {
      width: 100%;
      height: 100%;
    }
    .over {
      position: absolute;
      width: 100%;
      height: 100%;
      font-size: 36px;
      text-align: center;
      color: yellow;
      background: rgba(64, 64, 64, 0.5);
      top: 0;
      left: 0;
      z-index: 2;
      display: none;
    }
    span {
      margin-left: auto;
      margin-right: auto;
      background-color: white;
    }
    
    

提交回复
热议问题