Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS How to stop css keyframe animation?

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #34292
    Andy_H
    Participant

    Hello!

    I have an image of a record that is spinning on the page like this:

    html






    css


    /*Animations
    *************************/
    @-webkit-keyframes rotate-record {
    0% {-webkit-transform: rotate(0deg);}
    100% {-webkit-transform: rotate(360deg);}
    }
    @-moz-keyframes rotate-record {
    0% {-moz-transform: rotate(0deg);}
    100% {-moz-transform: rotate(360deg);}
    }

    /*Structure
    *************************/
    .record-label {position:absolute; top:0; left:0;}
    .rotate-image {
    -webkit-animation:rotate-record 3s infinite linear;
    -moz-animation:rotate-record 3s infinite linear;
    }
    .record-wrap {position:relative; height:250px; width:233px;}
    .record-wrap a {cursor:pointer;}
    .stop-play {background:#333; display:block; position:absolute; bottom:2px; left:0; width:14px; height:14px;}
    .stop-play:hover {background:#888;}

    js


    $('.stop-play').click(function() {
    $('.record-label').removeClass('rotate-image');
    });

    html: image and a stop button in a wrapper
    css: make it spin
    js: remove the rotate-image class

    The problem is when I remove the class that makes it rotate the record goes back to it’s status quo position 0deg. What I would want it to do: is to stop right there in that position. Is there a way?

    Or would it be just easier to do the whole thing with jQuery using .animate() and .stop(). See here.

    Thank you!!!!111 :)

    #86823
    Chris Coyier
    Keymaster

    There is a thing called the animation-play-state in which you can pause animations. http://dev.w3.org/csswg/css3-animations/#animation-events- Theoretically… I haven’t played with it at all, and I’m not even sure what the support is.

    #86832
    Chris Coyier
    Keymaster
    #86860
    Andy_H
    Participant

    Thanks Chris!

    #139818
    paulala
    Member

    Great thread! Thank you for posing and solving a problem that is both technically and conceptually interesting.

    #139820
    Kitty Giraudel
    Participant

    Theoretically… I haven’t played with it at all, and I’m not even sure what the support is.

    The same as animation if no mistake.

    #139821
    Paulie_D
    Member

    Thread is 2 years old….just saying.

    #139824
    Kitty Giraudel
    Participant

    Damn, I always forget to check dates..

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘CSS’ is closed to new topics and replies.