5

我在使用 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();
});

});

我会很感激你的帮助:)

4

3 回答 3

8

演示

使用mouseenterandmouseleave代替。

$(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-08-27T11:42:40.490 回答
1

尝试这个

$(document).ready(function() {
    $('.section-text').hide();

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

});
于 2013-08-27T11:50:17.797 回答
0

在 jQuery 中,当鼠标进入匹配的元素时,mouseover() 和 mouseenter() 事件都会触发。唯一不同的是子元素中“事件冒泡”句柄的方式参考:http ://www.mkyong.com/jquery/differ-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-08-27T11:49:59.990 回答