【问题标题】:How to check if DOM node is animating in jQuery如何检查 DOM 节点是否在 jQuery 中进行动画处理
【发布时间】:2013-08-06 12:52:15
【问题描述】:

我有 DOM 节点和单击处理程序,我需要在制作动画时禁用该操作。如何检查元素当前是否正在通过 jQuery 动画进行动画处理?

$('div').on('click', '.item', function() {
    if (/* this not animating */) {
        animate($(this));
    }
});

我是否需要在该元素上设置data('play'),以便在完成后清晰或有更好的方法。

【问题讨论】:

  • 当你说“动画”时,你指的是 jQuery 动画还是 CSS 过渡?
  • @FrédéricHamidi jQuery 动画。

标签: javascript jquery animation dom jquery-events


【解决方案1】:

尝试使用以下方法:

$('div').on('click', '.item', function() {
    $this = $(this); // cached so we don't wrap the same jquery object twice
    if (!$this.is(':animated')) {
        animate($this);
    }
});

查看:animated selector documentation

演示:http://jsfiddle.net/smerny/tBDL8/1/

【讨论】:

  • 我在 api.jquery.com 中搜索 :animating
  • 是的,这似乎更有意义,因为您正在检查它当前是否“动画”而不是它是否有动画,但我想动画它们意味着它处于动画状态。跨度>
【解决方案2】:

使用

$(element).is(":animated");

【讨论】:

    【解决方案3】:

    您可以使用:animated 选择器检查元素是否正在动画。

    if($(this).is(":animated")) { ... }
    

    欲了解更多信息,请查看:http://api.jquery.com/animated-selector/

    【讨论】:

      猜你喜欢
      • 2013-03-26
      • 2014-11-14
      • 1970-01-01
      • 2022-06-21
      • 1970-01-01
      • 2023-01-04
      • 1970-01-01
      • 2012-08-28
      相关资源
      最近更新 更多