Last Updated: February 25, 2016
· euantor

Using a callback with a Scriptaculous effect

Callbacks are commonplace in most jQuery functions such as .slideToggle(), .animate() etc. Sometimes (such as when working with MyBB) though you are forced to use other JavaScript libraries such as Prototype (with it's friend Scriptaculous). One such occasion came up recently and I found my self trying to use the standard jQuery style call back on Scriptaculous' Effect.toggle() only for it not to work (obviously). After a bit of searching I finally found the solution and here it is: the afterFinish option.

Effect.toggle(popup_id, 'blind', { // Our actual effect
    afterFinish: function() { // the function to run after the effect is complete
        // Function contents

It's not quite as obvious as how jQuery does it but I action think it makes slightly more sense. During my short time using Prototype recently I've slowly started to realise that it does quite a lot of things in ways that make much more sense than jQuery. That's not to say I'm not still a jQuery fan though.