gpt4 book ai didi

javascript - 组合动画结束时如何执行 Action ?

转载 作者:行者123 更新时间:2023-11-30 06:35:37 24 4
gpt4 key购买 nike

我是 Dojo 世界的新手,所以这可能是一些愚蠢的东西,让我很难受。

我有以下代码(去掉了不相关的东西):

define(["dojo/_base/declare", "dojo/fx", "dojo/on"],
function (declare, fx, on) {
return declare(null, {
executeTransition: function (continuation) {
var animation = fx.combine([
fx.slideTo({
duration: 1200,
node: this.node1, // node1 will be a valid node at the moment of execution
left: -this.node1.offsetWidth
}),
fx.slideTo({
duration: 1200,
node: this.node2, // node2 will be a valid node at the moment of execution
left: 0
})
]);

on(animation, "End", continuation);

animation.play();
}
});
}
);

按原样执行我的代码时,on 行失败,提示 Uncaught Error: Target must be an event emitter。但是作为一个动画,它应该已经是一个事件发射器了吗?

我为解决我的问题所做的一些背景研究:

reference guide to dojo.fxfx.combine 的结果视为任何其他动画。 API reference for dojo.fx只声明它返回一个实例。

无论如何,Dojo 1.8 animation tutorial具有与我尝试执行的示例完全相同的示例,只是它稍后将 fx.combine 的结果包装在 fx.chain 中(我不需要——或者我需要吗?)。

所以,我的问题是:使用 Dojo 1.8,我如何并行运行两个动画并在它们完成后执行一些代码?

最佳答案

阅读您的问题后,我决定进行调查。我发现,“目标必须是事件发射器” 错误仅在尝试从组合动画中捕获 onEnd 事件时发生。它不会发生在链式动画中。

经过一番挖掘后,我注意到组合动画似乎有一个 _connects 属性,这表明它使用的是旧的折旧 "dojo/_base/connect"功能。这可能是 Dojo 中的一个错误(或者更确切地说是在最近的升级中遗漏的代码)。看了一下 Dojo Trac但还没有找到任何东西,可能会为此开一张新票。

我可以想到两种解决方法:

  1. 使用 "dojo/_base/connect"

    connect.connect(animation, "onEnd", function(){
    // connect == dojo/base/connect
    })
  2. 直接连接到 onEnd 事件(或使用 "dojo/aspect" )

    animation.onEnd(function(){
    });

这两种方式都不是理想的,因为您可能必须将代码更改为 dojo/on将来某个日期的版本。

编辑: 看起来其他人已经将此报告为错误,see here .

关于javascript - 组合动画结束时如何执行 Action ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14737490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com