【问题标题】:How do I add a delay to this when hovering over for height change?当悬停在高度变化时,如何添加延迟?
【发布时间】:2012-11-08 02:01:55
【问题描述】:
$(function(){
    $("#top-img").hover(function(){
    $(this).stop().animate({height:"400px"},{queue:false,duration:700});
        }, 

        function() {
    $(this).stop().animate({height:"300px"},{queue:false,duration:700});
    });
});

这是我正在使用的代码,大部分都很简单。当我将鼠标悬停在 div #top-img 上时,它会从 300px 的高度(在 CSS 中设置)将其设置为动画到 400px 的高度。

我想稍微延迟一下,以便

  1. 人们必须在它运行前将鼠标悬停一秒钟,然后
  2. 您必须先离开它一秒钟,然后它才能返回 300px

【问题讨论】:

    标签: hover jquery-animate delay


    【解决方案1】:

    查看HoverIntent jQuery 插件。我过去使用过它,它非常易于使用和实现

    【讨论】:

      【解决方案2】:

      这种方法有效,但问题是当多次悬停和关闭悬停时,它并没有结束,而是一直上下移动。所以我需要一些如何从两者中添加我需要的东西。 .

      $(document).ready(function(){
          $("#top-img").hover(function(){
          $(this).delay(400).animate({height:400},1000);
      },function(){
      
          $(this).delay(300).animate({height:300},500);
          });
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-17
        • 2014-09-10
        • 2011-12-14
        • 1970-01-01
        • 2016-12-20
        • 1970-01-01
        • 1970-01-01
        • 2011-05-09
        相关资源
        最近更新 更多