使用zepto,是否可以对动画进行排队?
zepto.js 有一个用于动画元素的 API,它允许包含“完成”回调函数。 动画源
但是jquery 类型队列 API 似乎不受支持。
我想知道是否有一种内置方法可以使用 zepto 创建动画序列,或者我应该从某个地方捏一个队列函数?
此外,“完成”回调不传递任何参数,因此知道您处于动画序列的哪个阶段有点难看 - 也许有解决方法?
zepto.js has an API to animate elements, which allows to include a "done" callback function. animate source
however jquery type queue API doesn't seem to be supported.
I was wondering if there's a built-in approach for creating animation sequences with zepto or should i just pinch a queue function from somewhere?
also the "done" callback doesn't pass any parameters, so its bit ugly to know which stage of the anim sequence you are at - maybe theres a workaround for that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否会发现它有帮助,但我编写了一个小插件来对 zepto 动画进行排队:
示例用法:
I'm not sure if you will find it helpful but I wrote a litte plugin to queue zepto animations:
an example usage:
您可以传递给 zepto 的 anim(ate) 函数的回调仅在动画完成时调用。
假设在回调期间 css 属性与传入的属性相同是可以避免的。因此,如果您不直接传入它们,则可以重用该对象。
此外,在回调中,您始终可以使用
$.fn.css
函数来获取当前样式,尽管这可能不是最高效的方法。关于排队,使用动画回调,您可以通过调用带有嵌套回调的
$.fn.anim
来构建基本队列。如果您想要或需要更高级的队列,将 jQuery 队列作为插件移植到 zepto 应该没什么大不了的。
干杯
The Callback you can pass to zepto's anim(ate) function is only called when the animation is finished.
It is save to assume that during the callback the css properties are the same as those passed in. So if you don't pass them in directly you can reuse the object.
Also, inside the callback you can always use the
$.fn.css
function to get the current style, although this might not be the most performant way.Regarding queueing, using the animation callbacks you can build a rudimentary queue by calling
$.fn.anim
with nested callbacks.If you want or need more advanced queues, porting the jQuery queue to zepto as a plugin should be no big deal.
Cheers