mouseenter和mouseout更稳定的结果?

时间:2014-09-21 22:13:32

标签: jquery css jquery-plugins mouseenter mouseout

所以我想要一个很酷的功能,使用漂亮的彩色动画工具改变焦点内容区域的标题。好吧,它动画很好......但是当鼠标仍然在目标周围时,它会认为你立刻鼠标移动。有谁知道如何让它稳定?我正在考虑捕捉鼠标以及它是否位于“区域”区域内。这样做,但我不知道这是否更好?

        // Content Hovers

        $('.large-box > *').each(function(){

            $(this).mouseenter(function(){
                $(this).find('.column-header').animate({ 'backgroundColor': '#3e84d2' }, 'slow');
            });
            $(this).mouseout(function(){
                $(this).find('.column-header').animate({ 'backgroundColor': '#455c79' }, 'slow');
            });

        });

Soution:解决方案是使用mouseleave()代替mouseout()

1 个答案:

答案 0 :(得分:2)

使用mouseleave()而不是mouseout(),因为mouseout()也会触发子元素,并且应该与mouseover()而不是mouseenter()一起使用。

示例:http://api.jquery.com/mouseenter/

相关问题