Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery remove class after css animation played?

I have the css code:

body.start{-webkit-animation:srcb ease-in .4s 1;}

and just play once when entered the website

but the problem is while the animation done

the buttons in my site isn't works

how can I remove the body class "start" after animation done

or remove class delay x seconds after animation played?

like image 594
jk jk Avatar asked Dec 14 '12 18:12

jk jk


Video Answer


2 Answers

You can bind to the transitionend event (to all of them, actually):

$("body").on(
    "transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd",
    function() {
        $(this).removeClass("start");
    }
);

If you want to implement a delay, you can queue() the class removal operation:

$("body").on(
    "transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd",
    function() {
        $(this).delay(1000).queue(function() {  // Wait for 1 second.
            $(this).removeClass("start").dequeue();
        });
    }
);

Note: on() only exists since jQuery 1.7, if you are using an older release you will have to use bind() instead for the code above to work.

like image 62
Frédéric Hamidi Avatar answered Sep 22 '22 09:09

Frédéric Hamidi


Try

webkitAnimationEnd oanimationend msAnimationEnd animationend

instead of

transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd

This worked for me.

like image 27
zeno2k Avatar answered Sep 23 '22 09:09

zeno2k