2

There is a way to trigger an event after an animation is done? what's the cose for it? I'm very new with YUI libraries and i'm getting lost..

my cose now is

    var anim = new Y.Anim({
        node: node,
        duration: 1.0,
        easing: Y.Easing.easeOut
    });

...etc

Note: This applies to YUI2.

Fiver
  • 9,909
  • 9
  • 43
  • 63
Francesco
  • 24,839
  • 29
  • 105
  • 152

3 Answers3

1

Yup! Something like:

var myAnim = new YAHOO.util.Anim("yourId", {
   left: {from: 0, to:75}
}, 1);

myAnim.onComplete.subscribe(function() {
   alert('Done!');
});

See http://developer.yahoo.com/yui/examples/animation/index.html for more examples.

Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
1

To do something after an animation is done, you just need to listen to the "end" event:

var anim = new Y.Anim({
    node: node,
    duration: 1.0,
    easing: Y.Easing.easeOut,
    on: {
        end: function (e) {
            // your stuff here
        }
    }
});
juandopazo
  • 6,283
  • 2
  • 26
  • 29
0

The idea is, that since an animation takes time, you might want to be notified when the animation completes to perform any additional logic you might need: Here are a few uses for that event:

  1. Trigger additional animations once an animation completes. This can be on the same element or a completely different part of the UI.
  2. Remove the element from the DOM. Perhaps it was a popup-window, that once it is closed (with an animation), is no longer needed in the DOM
  3. Something other, like filling the element with content etc.
PatrikAkerstrand
  • 45,315
  • 11
  • 79
  • 94