【问题标题】:how to set time out for jquery hover function如何为jquery悬停功能设置超时
【发布时间】:2012-08-26 17:16:52
【问题描述】:

例如请看这些代码:

HTML:

<div id="hvr">hover me</div>
<div id="box" style="background:#ddd; width:100px; height:50px;"></div>

jQuery:

$(function(){
$("#hvr").hover(function(){

    $("#box").animate({width:'150px'},500);
    more animations/functions here ...

}, function(){

    $("#box").animate({width:'100px'},500);
    more animations/functions here ...
});

当我快速将鼠标悬停在文本上 3 次时,框会在每个完成后动画 3 次。 如何设置悬停超时,这将禁用悬停效果,直到第一个动画/功能[由于第一次悬停]完成?

【问题讨论】:

    标签: jquery timeout hover


    【解决方案1】:

    试试这个

    $(function(){
      $("#hvr").hover(function(){    
          $("#box").stop().animate({width:'150px'},500);   
      }, function(){    
          $("#box").stop().animate({width:'100px'},500);
      });
    });
    

    http://api.jquery.com/stop/

    【讨论】:

    • 这不符合 OP 的要求:“我怎样才能为悬停设置一个超时时间,这将在第一个动画完成之前禁用悬停效果”。
    • 实际上它有效,但仅适用于一级动画。如果我为示例添加 2 多行动画,它将不起作用。我想为所有内部函数设置悬停超时..
    猜你喜欢
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多