jquery - 在悬停时停止不必要的 div 重复

标签 jquery animation html

尊敬的专家,

我有一个问题。我是 Jquery 的新手,我正在尝试根据下面给出的示例代码使用 div 动画。发生的情况是,当将鼠标多次悬停在 div 上时,操作会自行复制并导致我想以某种方式避免的可用性行为。有没有办法让功能检查鼠标行为,例如 div 在给定时间内悬停以避免不必要的多次激活? 我希望我解释得足够好。

感谢您的输入。

$(document).ready(function() {

$("#expand_smoke").hover(
         //on mouseover
          function() {
              $(this).animate({
              height: '+=125' //adds 125px
               }, 'slow' //sets animation speed to slow
              );
           },
         //on mouseout
          function() {
              $(this).stop()
             $(this).animate({
             height: '60' //changes back to 60px
        }, 'slow'
      );
    }
  );

});

最佳答案

你为什么不这样做呢?

$("#expand_smoke").hover(
    function() {
        $(this).stop().animate({ height: '200' }, 'slow');
    },
    function() {
        $(this).stop().animate({ height: '60' }, 'slow');
    }
);

关于jquery - 在悬停时停止不必要的 div 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12698783/

相关文章:

javascript - Dojo:Div 标签问题

javascript - CSS 相当于 .attr ("data-html", "true")

JQuery 验证多个复选框组

asp.net - 如何检查文件是否准备好?

jQuery 在 50 个字符后的文本中添加一个 <br>

wpf - 完全通过代码 WPF 执行翻转动画

javascript - 从 .html() 中排除一些元素;在 jQuery 中

jquery - "slow"、 "normal"和 "fast"在 jQuery 中代表多少毫秒?

Android:动画完成后更新 LinearLayout 位置

javascript - 在 Titanium 桌面应用程序中编辑默认菜单