2010-12-07 10 views
0

どうしたらいいですか?マウスオーバーする要素

if($('.element').mouseover() == true) 
{ 
} 
else 
{ 
} 

何か他のことがなければ、モーズが要素の上にあるときを知りたい。

これは現在動作する完全なコードです。私はjQueryのは、使用する構文は、何が正常に書くだろうと異なっている

$(".element").hover(
    function() { 
    //this is mouseover 
    }, 
    function() { 
    //this is mouseout 
    } 
); 
+0

あなたがしたいことを知らせてください、すでにmouseoverのためのavailble availbleがあります、それはmouseoverかどうかを確認する必要はありません//何かがない場合作業 – kobe

答えて

2

と実施例であります素子。

mouseenterとmouseoutを使用する理由があります。ネストされた要素と関連しています。あなたはそれを見ることができますhere

+0

私はmouseleave()がそのmouseout()と違うと思います。私はそれを使用し、すべての私の問題はなくなった。ありがとう。 – JamesTBennett

0
$(".element").mouseenter(function() { 

    alert('Mouse over the element'); 

}).mouseleave(function() { 

    alert('Mouse out'); 

}); 
0

1以上を処分しました。彼らのタグラインは、 "あなたがJavaScriptコードを書く方法を変える"のようなものでした。次のようにmouseover()を使用する必要があります。

$('.element').mouseover(function() { 
    // Use $(this) to access the element where the mouse is entering. 
}).mouseout(function() { 
    // Use $(this) to access the element where the mouse is exiting. 
}); 

同様のmouseenter()メソッドとmouseleave()メソッドにも注意してください。公式の文書はhttp://api.jquery.com/mouseover/です。ここで

0

を使用するelagentあるone..which最新のif文...

$('.product_image').hover(function(){ 
    var image = $(this).attr('class'); 
    image = '.' + image.substring(14); 
    $(image).fadeIn(); 
}); 
$('.product_disc').mouseleave(function(){ 
    $('.product_disc').fadeOut(); 
}); 
0

は実施例である:

http://www.jsfiddle.net/mSkx5/1/

これは、jQueryののhover機能を使用しています。

幸運を祈る!

EDIT:

$('.element').mouseenter(function() { 
    $(this).addClass('hover'); 
}).mouseleave(function(){ 
    $(this).removeClass('hover'); 
}); 

今、あなたはマウスが上にあるかどうかを確認するためにis methodを使用することができます:ここmouseover私はこのパターンをたくさん使う

http://www.jsfiddle.net/mSkx5/2/

関連する問題