【问题标题】:Jquery mouseover and mouseout keeps flashingjquery mouseover和mouseout一直闪烁
【发布时间】:2013-08-30 03:18:15
【问题描述】:

我在使用 jQuery MouseOut 和 MouseOver 时遇到了一些问题。

每次我将鼠标悬停在选定的 div 上时,都会出现需要显示的子 div。但是,它开始闪烁。

我不知道为什么。我已经在 J​​sFiddle 上发布了代码。

http://jsfiddle.net/Dn6Rq/

这是 HTML 代码:

<div class="section-item-portal">
<div class="section-text">Lorem Ipsum Dolor Sit Amet, Lorem Ipsum Dolor Sit Amet, Lorem Ipsum Dolor Sit Amet, Lorem Ipsum Dolor Sit Amet, Lorem Ipsum Dolor Sit Amet, Lorem Ipsum Dolor Sit Amet, </div>
</div>

这里是 jQuery:

 $(document).ready(function () {

$('.section-text').hide();

$('.section-item-portal').mouseover(function () {
    $(this).children('.section-text').fadeIn();
});

$('.section-item-portal').mouseout(function () {
    $(this).children('.section-text').fadeOut();
});

});

感谢您的帮助:)

【问题讨论】:

    标签: jquery mouseover mouseout


    【解决方案1】:

    DEMO

    请改用mouseentermouseleave

    $(document).ready(function () {
    
        $('.section-text').hide();
    
        $('.section-item-portal').mouseenter(function () {
            $(this).children('.section-text').fadeIn();
        });
    
        $('.section-item-portal').mouseleave(function () {
            $(this).children('.section-text').fadeOut();
        });
    
    });
    

    【讨论】:

    • 完美,非常感谢:)
    【解决方案2】:

    试试这个

    $(document).ready(function() {
        $('.section-text').hide();
    
        $('.section-item-portal').hover(function() {
            $(this).children('.section-text').fadeIn();
        },function(){
            $(this).children('.section-text').fadeOut();
        });
    
    });
    

    【讨论】:

      【解决方案3】:

      在 jQuery 中,当鼠标进入匹配的元素时,mouseover() 和 mouseenter() 事件都会触发。唯一不同的是子元素中“事件冒泡”句柄的方式 参考:http://www.mkyong.com/jquery/different-between-mouseover-and-mouseenter-in-jquery/

      请在 jsfiddle 中找到答案.. http://jsfiddle.net/Dn6Rq/1/

      $(document).ready(function () {
      
          $('.section-text').hide();
      
          $('.section-item-portal').mouseenter(function () {
              $(this).children('.section-text').fadeIn();
          });
      
          $('.section-item-portal').mouseleave(function () {
              $(this).children('.section-text').fadeOut();
          });
      
      });
      

      【讨论】:

        猜你喜欢
        • 2013-02-11
        • 1970-01-01
        • 1970-01-01
        • 2011-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-03
        • 1970-01-01
        相关资源
        最近更新 更多