简体   繁体   English

如何在Dojo中停止动画

[英]How to stop animation in Dojo

Using Dojo 1.9, I'm playing some animations like this: 使用Dojo 1.9,我正在播放一些动画,如下所示:

that.fadeOutActive = baseFx.fadeOut({ node: "active-container", duration: 1000, delay: 3000 });
that.fadeInInactive = baseFx.fadeIn({ node: "inactive-container", duration: 1000, delay: 3000 });
coreFx.combine([that.fadeOutActive, that.fadeInInactive]).play();

and then try to stop them on an event, like this: 然后尝试在事件中阻止它们,如下所示:

coreFx.combine([that.fadeOutActive, that.fadeInInactive]).stop();

The problem is, this prevents the animation from firing (which is the desired behavior), but it doesn't stop it if it had already begun (which is the problem). 问题是,这阻止了动画的触发(这是所需的行为),但是如果动画已经开始,它并不会停止动画(这是问题)。 How can I stop the animation, if I can at all? 如果可以的话,如何停止动画?

EDIT: It turns out my problem was not in the code I've posted, it was in detecting if the animation is in progress. 编辑:原来我的问题不在我发布的代码中,而是在检测动画是否在进行中。

dojo/fx::combine() is a helper function that can take a list of dojo/_base/fx::Animation objects and combine them so that their effects all run in parallel. dojo / fx :: combine()是一个辅助函数,可以获取dojo / _base / fx :: Animation对象的列表并将其组合在一起,以便它们的效果都可以并行运行。 With this function animations that affect multiple nodes can be generated and executed at the same time. 使用此功能,可以同时生成和执行影响多个节点的动画。

You are using coreFx.combine to simultaneously fadeIn one element and fadOut another element. 您正在使用coreFx.combine同时fadeIn一个元素,并fadOut另一个元素。

Instead of creating a new combined Animation you should store a reference to the existing combined animation and then use that reference to stop the combined animation: 代替创建新的组合动画,您应该存储对现有组合动画的引用,然后使用该引用停止组合动画:

that.fadeOutActive = baseFx.fadeOut({ node: "active-container", duration: 1000, delay: 3000 }).play();
that.fadeInInactive = baseFx.fadeIn({ node: "inactive-container", duration: 1000, delay: 3000 }).play();
that.combinedAnim = coreFx.combine([that.fadeOutActive, that.fadeInInactive]).play();

and then later: 然后再:

that.combinedAnim.stop();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM