Jquery在鼠标悬停后等待3秒

Jquery在鼠标悬停后等待3秒,jquery,Jquery,我有这个jquery代码 $(".y_e").mouseover(function(){ $(this).children(".Photopreview").show("fast"); $(this).mouseleave(function(){ $(this).children(".Photopreview").hide("fast"); }) }); 这个html <div class="y_e">

我有这个jquery代码

$(".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>


用户鼠标在y_e上移动后,我如何等待3秒钟?

您可以使用setTimeout进行等待

$('.y_e').mouseover(function() {
  setTimeout(function() {
    // The stuff you want to do when your three seconds are over.
  }, 3000)
});

您可以使用setTimeout进行等待

$('.y_e').mouseover(function() {
  setTimeout(function() {
    // The stuff you want to do when your three seconds are over.
  }, 3000)
});

尝试使用匿名函数实现setTimeout

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

尝试使用匿名函数实现setTimeout

$(".y_e").mouseover(function(){
    setTimeout(function() {
        $(this).children(".Photopreview").show("fast");
        $(this).mouseleave(function(){
            $(this).children(".Photopreview").hide("fast");
        })        
    }, 3000);
});
您可以像下面的代码一样使用“delay”jquery方法

$(".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");
});
注意:不要在其他事件监听器中注册事件监听器,因为这将为同一事件类型注册多个监听器。

您可以像下面的代码一样使用“延迟”jquery方法

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

注意:不要在其他事件监听器中注册事件监听器,因为这将为同一事件类型注册多个监听器。

然后,如果我在3000中鼠标移出,它仍将显示它。当您执行鼠标移出时,setTimeout中的函数将立即“激活”,但仅在3秒后执行。无论你的鼠标在哪里。这就是为什么我在寻找其他方法,你可能想澄清你真正想要的是什么。我没有明白你说的话。然后,如果我在那3000中鼠标移出,它仍然会显示它。当你进行鼠标移动时,setTimeout内的函数会立即“激活”,但只在3秒钟后执行。无论你的鼠标在哪里。这就是为什么我在寻找其他方法。你可能想澄清你真正想要的是什么。我没有得到你说的。你应该把$(这个)。mouseleve换成$(“.y_e”)。mouseleve你应该把$(这个)。mouseleve换成$(“.y_e”)。mouseleve可能的重复