Jquery mouseover and mouseout keeps flashing
Asked Answered
G

3

5

I am having some issues with jQuery MouseOut and MouseOver.

Every time I hover over the selected div, the child div that needs to show appears. however, it starts flashing.

I have no idea why. I have posted the code up on JsFiddle.

http://jsfiddle.net/Dn6Rq/

Here is the HTML code:

<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>

Here is the 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();
});

});

I would appreciate all your help :)

Gunflint answered 27/8, 2013 at 11:39 Comment(0)
F
8

DEMO

Use mouseenter and mouseleave instead.

$(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();
    });

});
Frannie answered 27/8, 2013 at 11:42 Comment(0)
A
1

try this

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

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

});
Anecdote answered 27/8, 2013 at 11:50 Comment(0)
A
0

In jQuery, both mouseover() and mouseenter() events are fire when the mouse enters the matched element. The only different is in the way of the “event bubbling” handle in child element Ref:http://www.mkyong.com/jquery/different-between-mouseover-and-mouseenter-in-jquery/

Please find the answer in 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();
    });

});
Ably answered 27/8, 2013 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.