【问题标题】:How can one set a sequential delay on adding a class?如何设置添加类的顺序延迟?
【发布时间】:2015-10-14 04:37:06
【问题描述】:

我正在使用 jQuery UI 插件和最新的 jQuery。

我想依次添加类,一个一个地添加到我的元素数组中。现在我有这个:

$(@el).addClass("gridBoxComplete", 400, "easeOutBounce").delay(800)

其中@el 是数组中的当前元素。但是,这不会在迭代中的下一个项目运行之前延迟此对象。我的这个动画大致是基于这个想法..

$(@).hide().each (index) ->
  $(@)
    .delay(index * 100)
    .fadeIn 500

【问题讨论】:

  • 我不知道 cofeecrap 是做什么的,但delay() 是用于动画,而不是用于添加类,请使用超时。
  • 你们中的任何一个人都知道我可以阅读的对咖啡脚本的批评的好来源吗?到目前为止,我过得很开心..

标签: javascript jquery animation coffeescript underscore.js


【解决方案1】:

delay() 延迟动画,而不是类名更改或其他代码执行。如果您想要通用的执行延迟,请使用setTimeout 或类似的东西:

$.fn.wait = function(ms, callback) {
  return this.each(function() {
    setTimeout(callback.bind(this), ms)
  })
}

$(@el).addClass("gridBoxComplete", 400, "easeOutBounce").wait(800, function() {
    $(this).addClass("something");
});

【讨论】:

  • 嗯..这个自定义函数返回unexpected identifier
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-04
  • 1970-01-01
  • 1970-01-01
  • 2014-10-21
  • 2015-07-24
  • 2014-01-07
相关资源
最近更新 更多