简体   繁体   English

在使用Prototype JS完成前一个功能后如何执行功能

[英]How to execute a function after the previous has finished using Prototype JS

In my example, I want to remove a class name from one element only after a fade out of another element is completed. 在我的示例中,我只想在淡出另一个元素之后才从一个元素中删除类名。 Here is my code thus far: 到目前为止,这是我的代码:

    $('search-box').observe('click', function(e) {
        $('question-box').fade();
        $('faq-box').removeClassName('left-60');
    });

As you can see these will execute one after the other, but as the element fades out slowly it will look like its executing at the same time. 如您所见,它们将一个接一个地执行,但是随着元素逐渐淡出,它看起来像是在同时执行。 I want to wait to the fade completes before I remove the class name. 我要等到淡入淡出完成,然后再删除类名称。

Any suggestions? 有什么建议么? Would a callback work here? 回调在这里可以工作吗? Examples would be greatly appreciated. 示例将不胜感激。

Ben

Use the afterFinish callback to execute the function after the fade is done: 淡入完成后,使用afterFinish回调执行函数:

$('question-box').fade({
    afterFinish: function() {
        $('faq-box').removeClassName('left-60');
    }
});

See the Core Effects Overview for the options common to all the script.aculo.us effects. 有关所有script.aculo.us效果共有的选项,请参见“ 核心效果概述 ”。

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

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