3

I have the following infinite animation running from the start that acts as a page loader:

@-webkit-keyframes spinX {
    100% {
        -webkit-transform:rotate(360deg);
    }
}

And on window load i m running the following JS:

window.onload = function(){
    var _logo_x = document.getElementById("logo-x");
    _logo_x.addEventListener("animationiteration", introLogo(_logo_x), false);
}
function introLogo(_ele)
{
  _ele.removeClass('rotate');
}

The problem that i m facing is that it cuts the current iteration instead of waiting for it. Fiddle

4
  • Try adding a transition to the element. Commented Mar 3, 2014 at 20:21
  • @minitech as in the rotate effect to the element instead of the class ? Commented Mar 3, 2014 at 20:25
  • Couldn't you just add a play state with JS? developer.mozilla.org/en-US/docs/Web/CSS/animation-play-state Commented Mar 3, 2014 at 21:15
  • @Paulie_D the animation is infinite, how is this relevant to detecting when the window is loaded and finish the last iteration ? Commented Mar 3, 2014 at 21:39

1 Answer 1

2
_logo_x.addEventListener("animationiteration", introLogo(_logo_x), false);

Is equivalent to:

introLogo(_logo_x);
_logo_x.addEventListener("animationiteration", undefined, false);

You want:

_logo_x.addEventListener("animationiteration", function() {introLogo(_logo_x)}, false);
Sign up to request clarification or add additional context in comments.

5 Comments

It no longer calls introLogo(); I m guessing animationiteration isn't working, i tried the vendor prefix variants and transitionend still nothing.
@PatsyIssa i modified your fiddle as stated in this answer, and it DO work
@CrisimIlNumenoreano care to share said modified fiddle.
@bjb568 turns out it was the "webkitAnimationIteration" syntax, cheers.
@Patsy Oh. :P Those dern vendor prefixes. So unhelpful, yet so annoying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.