Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 Rotate from 0 to 90 then 90 to 180

Tags:

css

animation

I have an object rotating 360 degrees using CSS3's rotate animation. However, the code (linked below) rotates the image 360 degrees then repeats the same animation.

I want to rotate it 360 degrees, pause every 90 degress and have infinite rotating.

Any help would be much appreciated.

Thanks

.image {
position: absolute;
top: 50%;
left: 50%;
width: 120px;
height: 120px;
margin:-60px 0 0 -60px;
-webkit-animation:spin 1s ease-in-out infinite;
-moz-animation:spin 1s linear infinite;
animation:spin 1s linear infinite;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }

Here is a JSFiddle for the project

like image 665
David Ingledow Avatar asked Aug 16 '13 14:08

David Ingledow


1 Answers

You need to add additional points in your keyframe:

Fiddle

@-webkit-keyframes rotate {
  0% { -webkit-transform: rotate(0deg); }
  20% { -webkit-transform: rotate(90deg); }
  25% { -webkit-transform: rotate(90deg); }
  45% { -webkit-transform: rotate(180deg); }
  50% { -webkit-transform: rotate(180deg); }
  70% { -webkit-transform: rotate(270deg); }
  75% { -webkit-transform: rotate(270deg); }
  100% { -webkit-transform: rotate(360deg); }
}

.animation-rotate {
    -webkit-animation-name: rotate; 
    -webkit-animation-duration: 4.5s; 
    -webkit-animation-iteration-count: infinite;
    -webkit-transition-timing-function: linear;
}
like image 59
dc5 Avatar answered Oct 02 '22 06:10

dc5