2016-07-09 9 views
0

後、私は私がy_eのユーザーマウスオーバーした後、3秒待つことができますどのようにこのjqueryのコードはjqueryの3秒待って、マウスオーバー

$(".y_e").mouseover(function(){ 
     $(this).children(".Photopreview").show("fast"); 
     $(this).mouseleave(function(){ 
      $(this).children(".Photopreview").hide("fast"); 
     }) 
}); 

このHTML

 <div class="y_e"> 
     <div class="Photopreview"> 
     <img src="../uploads/a.jpg"/> 
     <div class="Arrow_down" ></div> 
     </div> 
    </div> 

を持っていますか?

+0

[2秒以上マウスを置くと、他に何も表示されませんか?](http://stackoverflow.com/questions/11263636/if-mouse-over-for-over-2forsecover-show-) -else-dont) – billynoah

答えて

0
あなたが使用することができます

"遅延" jqueryのメソッド匿名関数でのsetTimeoutを実装してみ

$(".y_e").mouseover(function(){ 
    $(this).children(".Photopreview").stop(true,true).delay(3000).show("fast"); 
}); 
$(this).mouseleave(function(){ 
    $(this).children(".Photopreview").stop(true,true).hide("fast"); 
}); 

注:他の内側にイベントリスナーを登録しませんこれは、同じイベントタイプに対して複数のリスナーを登録するためです。

+0

$( "。y_e")に$(this).mousleaveを変更する必要がありますmouseleave –

+0

はい、ありがとう、 – mdameer

1

待ち時間の目的でsetTimeoutを使用できます。

​​
+0

それから私はmouseoutを3000にしてもまだそれを表示します –

+0

マウスオーバーをすると、setTimeoutの中の関数は直ちに "起動"されますが、3秒後にのみ実行されます。あなたのマウスがどこにあっても。 – 1sloc

+0

それは私が他の方法を探している理由です。 –

1

次のコードのような

$(".y_e").mouseover(function(){ 
    setTimeout(function() { 
     $(this).children(".Photopreview").show("fast"); 
     $(this).mouseleave(function(){ 
      $(this).children(".Photopreview").hide("fast"); 
     })   
    }, 3000); 
}); 
関連する問題