Jquery mouseenter() vs mouseover()

前端 未结 7 2147
梦如初夏
梦如初夏 2020-11-22 07:58

So after reading a recently answered question i am unclear if i really understand the difference between the mouseenter() and mouseover(). The post

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 08:29

    You see the behavior when your target element contains child elements:

    http://jsfiddle.net/ZCWvJ/7/

    Each time your mouse enters or leaves a child element, mouseover is triggered, but not mouseenter.

    $('#my_div').bind("mouseover mouseenter", function(e) {
      var el = $("#" + e.type);
      var n = +el.text();
      el.text(++n);
    });
    #my_div {
      padding: 0 20px 20px 0;
      background-color: #eee;
      margin-bottom: 10px;
      width: 90px;
      overflow: hidden;
    }
    
    #my_div>div {
      float: left;
      margin: 20px 0 0 20px;
      height: 25px;
      width: 25px;
      background-color: #aaa;
    }
    
    
    
    MouseEnter: 0
    MouseOver: 0

提交回复
热议问题