AI编程助手
AI免费问答

jQuery事件中mouseover与mouseenter的区别

黄舟   2017-06-28 14:03   1384浏览 原创

在我们的页面中经常会用到mouseover与mouseout事件来给页面添加更好的渲染效果,但如果触发mouseover事件的元素有子元素的话,会造成闪烁的效果,看着很不舒服,这是因为mouseover与mouseout不论鼠标指针穿过被选元素或其子元素,都会触发。而mouseenter与mouseleave只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件。


        
  •         
                
                    @@##@@             
                
                                                  
                
            
            

    study

            
        
//1
$(".con-ul").on({
        mouseenter: function() {
            $(this).find(".dask").stop(true,true).fadeIn(600);
            $(this).find(".input").stop(true,true).fadeIn(600);
        },
        mouseleave: function() {
            $(this).find(".dask").stop(true,true).fadeOut(300);
            $(this).find(".input").stop(true,true).fadeOut(300);
        }
    }, ".con-oneimg");

//2
$(".con-ul").on({
        mouseover: function() {
            $(this).find(".dask").stop(true,true).fadeIn(600);
            $(this).find(".input").stop(true,true).fadeIn(600);
        },
        mouseout: function() {
            $(this).find(".dask").stop(true,true).fadeOut(300);
            $(this).find(".input").stop(true,true).fadeOut(300);
        }
    }, ".con-oneimg");

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。