質問

i have a problem with this code (i made a jsfiddle http://jsfiddle.net/r2y8J/).

$(document).ready(function() {
 /*$(".bulletProj").mouseenter(function () {
     console.log("You're Over!");
     $(".caption").animate(
        {top: "0px"},
        300, function() {
            console.log("i slided");
        });
    });
    $(".bulletProj").mouseleave(function() {
    $(".caption").animate(
        {top: "-200px"},
        300, function() {
            console.log("i left");
        });
    });*/
    $(".bulletProj").mouseenter(function() {
       console.log("mous is over");
       $(".caption").toggle();
    }).mouseleave(function () {
       console.log("mous leaves");
       $(".caption").toggle();
  });
});

Part of the code is commented since I tried more ways.

What I want to do is to have a div with some text and a bg image, and when the mouse is over it another div should slideDown with a button. The problem is that I tried .mouseover .mouseout, .mouseeneter and .mouseleave but it keep flickering. I found that when i'm over the text it stops but if I am in a blank space of the div it continues flickering. Anyone has an idea? Thanks very much.

役に立ちましたか?

解決

try this:

$(document).ready(function() {  
    $(".bulletProj,.caption").mouseenter(function() {              
         $(".caption").toggle();        
    }).mouseleave(function () {     
        $(".caption").hide();
    });
});

working fiddle here: http://jsfiddle.net/r2y8J/4/

I hope it helps.

他のヒント

You can easily use

.caption{pointer-events:none}

http://jsfiddle.net/r2y8J/5/

Try this.

$(".bulletProj").mouseenter(function() {
        console.log("mous is over");
        $(".caption").toggle();
    }).mouseleave(function () {
        console.log("mous leaves");
        stopImmediatePropagation();
        $(".caption").toggle();

    });

I have faced a similar problem, in my case i have used css: opacity like below to stop flickering

css:

.caption {
width: 300px;
height: 200px;
background-color: #69adf1;
position: absolute;
opacity:0;
}

JQuery:

$(".caption").mouseenter(function(){
$(this).css('opacity','1');
})
$(".bulletProj").mouseenter(function() {
    console.log("mous is over");
    $(".caption").css('opacity','1');
}).mouseleave(function () {
    console.log("mous leaves");
    $(".caption").css('opacity','0');
});

Working Fiddle

var caption = $(".caption");
$(".bulletWrapper").hover(function(){
    console.log("mous is over");
    caption.toggle();
}, function(){
    console.log("mous leaves");
    caption.toggle();
});

or

$(".bulletWrapper").bind("mouseenter mouseleave", function(){
    $(".caption").toggle();
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top