Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS spinning wheel stop after 5 seconds?

Tags:

css

I am using this CSS code I found on fiddle to spin my wheel:

http://jsfiddle.net/gaby/9Ryvs/7/

div {
    margin: 20px;
    width: 100px;
    height: 100px;
    background: #f00;
    -webkit-animation-name: spin;
    -webkit-animation-duration: 4000ms;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
    -moz-animation-name: spin;
    -moz-animation-duration: 4000ms;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: linear;
    -ms-animation-name: spin;
    -ms-animation-duration: 4000ms;
    -ms-animation-iteration-count: infinite;
    -ms-animation-timing-function: linear;

    animation-name: spin;
    animation-duration: 4000ms;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}
@-ms-keyframes spin {
    from { -ms-transform: rotate(0deg); }
    to { -ms-transform: rotate(360deg); }
}
@-moz-keyframes spin {
    from { -moz-transform: rotate(0deg); }
    to { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
    from {
        transform:rotate(0deg);
    }
    to {
        transform:rotate(360deg);
    }
}

Basically I want to stop the spinning exactly after it reaches 1800 Degress, and then go back to 0 so I can spin it again later.

Is that possible to do?

like image 711
Jony Kale Avatar asked Nov 13 '22 03:11

Jony Kale


1 Answers

You can just set the animation-iteration-count appropriately.

1800 degrees = 5 full rotations (5 * 360)

-webkit-animation-iteration-count:5;
-moz-animation-iteration-count:5;
-ms-animation-iteration-count:5;
-o-animation-iteration-count:5;
animation-iteration-count:5;

It should automatically reset to 0 upon completion.

This documentation might give some more context.

EDIT

Updated your jsFiddle. Side note, you should consider including -o-animation items in there as well, in case they have Opera v12. Also, consider shorthand.

-webkit-animation:spin 4000ms linear 0s 5;
-moz-animation:spin 4000ms linear 0s 5;
-ms-animation:spin 4000ms linear 0s 5;
-o-animation:spin 4000ms linear 0s 5;
animation:spin 4000ms linear 0s 5;
like image 96
PlantTheIdea Avatar answered Nov 27 '22 23:11

PlantTheIdea