0

I am using ToggleClass to trigger an animation from css and need to call a function after the animation has ended. I'm calling a function from the typed.js library.

 $('.anim').toggleClass('slide-down');
      $(".sentence").typed({
        strings: ["first sentence", "Second sentence." ],
        typeSpeed: 45,
        backDelay: 500,
        callback: function(){}
});

how can I make the typed function wait till the toggleClass has finished?

Farzan
  • 607
  • 1
  • 8
  • 27
  • possible duplicate of [how to wait for css transition to finish before applying next class](http://stackoverflow.com/questions/18592933/how-to-wait-for-css-transition-to-finish-before-applying-next-class) – Tushar Gupta - curioustushar Mar 22 '14 at 12:31

1 Answers1

6

You can wait for the animationend event

$('.anim').toggleClass('slide-down').one('animationend', function () {
    $(".sentence").typed({
        strings: ["first sentence", "Second sentence."],
        typeSpeed: 45,
        backDelay: 500,
        callback: function () {}
    });
});

Or if you are using transition, then use transitionend

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531