animate-css / animate.css

🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
https://animate.style/
Other
80.82k stars 16.24k forks source link

Restart animation #855

Closed Salitehkat closed 6 years ago

Salitehkat commented 6 years ago

Hi, Does anyone have an updated trick to restart an animation? I am currently using this:

videoLayer.classList.remove('animated', 'fadeOut'); videoLayer.classList.add('animated', 'fadeIn');

It might be not the best approach.

Thanks so much for any tip.

warengonzaga commented 6 years ago

Hello @Salitehkat based on the documentation...

$.fn.extend({
  animateCss: function(animationName, callback) {
    var animationEnd = (function(el) {
      var animations = {
        animation: 'animationend',
        OAnimation: 'oAnimationEnd',
        MozAnimation: 'mozAnimationEnd',
        WebkitAnimation: 'webkitAnimationEnd',
      };

      for (var t in animations) {
        if (el.style[t] !== undefined) {
          return animations[t];
        }
      }
    })(document.createElement('div'));

    this.addClass('animated ' + animationName).one(animationEnd, function() {
      $(this).removeClass('animated ' + animationName);

      if (typeof callback === 'function') callback();
    });

    return this;
  },
});
And use it like this:

$('#yourElement').animateCss('bounce');
or;
$('#yourElement').animateCss('bounce', function() {
  // Do somthing after animation
});

hope helps...

Salitehkat commented 6 years ago

Thank you!!!!

warengonzaga commented 6 years ago

@daneden and @eltonmesquita please close this thanks!