Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn Off CSS3 Animation With jQuery?

I have an object that has an animation when the page is loaded:

.logo-mark {
        -webkit-animation: spin 2s 1 cubic-bezier(0.000, 0.000, 0.230, 1.000);
            -moz-animation: spin 2s 1 cubic-bezier(0.000, 0.000, 0.230, 1.000);
            -ms-animation: spin 2s 1 cubic-bezier(0.000, 0.000, 0.230, 1.000);
            animation: spin 2s 1 cubic-bezier(0.000, 0.000, 0.230, 1.000);
    }

At a certain time, I want JavaScript to turn on a specific animation that occurs endlessly, until JavaScript stops said animation. So I simply made another class named .logo-loading, and at certain times, jQuery does an addClass and a removeClass.

.logo-loading {
            -webkit-animation: spin 4s infinite linear;
                -moz-animation: spin 4s infinite linear;
                -ms-animation: spin 4s infinite linear;
                animation: spin 4s infinite linear;
        }

However, when JavaScript removes the class, the object just keeps rotating no matter what. Is there anything I can do here?

like image 815
John Shammas Avatar asked Feb 19 '12 22:02

John Shammas


People also ask

Why is stop () method added before calling animate () in jQuery?

Why do we usually add the stop() method before calling animate() ? stop() halts the execution of the scripts on the page until the animation has finished. stop() ends any currently running animations on the element, and prevents conflicts and pile-ups. We tell jQuery that the animation has to be stopped at some point.

How do you stop animation?

To remove more than one animation effect from text or an object, in the Animation Pane, press Ctrl, click each animation effect that you want to remove, and then press Delete. To remove all animation effects from text or an object, click the object that you want to stop animating.


1 Answers

You can just override that CSS properties with "none" to every animation

function stopAnimation(element)
{
    $(element).css("-webkit-animation", "none");
    $(element).css("-moz-animation", "none");
    $(element).css("-ms-animation", "none");
    $(element).css("animation", "none");
}

so you can stop animation simply calling this function...

like image 169
Sinisa Bobic Avatar answered Sep 18 '22 19:09

Sinisa Bobic