Forum: Rails Spinoffs (closed, excessive spam) Scriptaculous Effect.toggle callback

Posted by wellmoon (Guest)
on 2008-06-19 12:45
(Received via mailing list)
Hello,

I'm using the Effect.toggle('myElem', 'slide') effect to open and
close a div. I'd like a callback function to be executed once the
effect has finished. I tried adding the function like this:

Effect.toggle('myElem', 'slide', function() {
  //do something fun here
});

But this did not work. How can I execute a function once the effect
has finished?  I tried just adding a normal function after the
Effect.toggle line of code, but the function gets executed before the
effect has finished...

I'd like to avoid using setTimeout if possible....
Posted by wellmoon (Guest)
on 2008-06-19 13:30
(Received via mailing list)
Furthermore, I discovered the afterFinish callback but it still does
not work :(

I have used the code:

Effect.toggle('myElem', 'slide', { afterFinish:alert("it has
finished") });

But the alert is displayed before the effect has finished...

Is this a bug?
Posted by wellmoon (Guest)
on 2008-06-19 13:38
(Received via mailing list)
Sorry, my bad. I got it now. Inline functions do not work so well,
defining the function as a variable elsewhere and calling it in the
afterFinish property works fine...

var myFunc = function() {
  //it works...
}

Effect.toggle('myElem, 'slide', { afterFinish: myFunc });
Posted by Frederick Polgardy (Guest)
on 2008-06-19 15:04
(Received via mailing list)
You can still define it inline:

Effect.toggle('myElem, 'slide', {
  afterFinish: function() {
   //it works...
   }
});

But good job sleuthing around and making it work. ;-)

-Fred

On Thu, Jun 19, 2008 at 6:37 AM, wellmoon <danwellman@gmail.com> wrote:

>
> Sorry, my bad. I got it now. Inline functions do not work so well,
> defining the function as a variable elsewhere and calling it in the
> afterFinish property works fine...
>
> var myFunc = function() {
>  //it works...
> }
>
> Effect.toggle('myElem, 'slide', { afterFinish: myFunc });


--
Science answers questions; philosophy questions answers.
This topic is locked and can not be replied to.