Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS endless rotation animation

I want to make a rotation of my loading icon by CSS.

I have an icon and the following code:

<style> #test {     width: 32px;     height: 32px;     background: url('refresh.png'); }  .rotating {     -webkit-transform: rotate(360deg);     -webkit-transition-duration: 1s;     -webkit-transition-delay: now;     -webkit-animation-timing-function: linear;     -webkit-animation-iteration-count: infinite; } </style>  <div id='test' class='rotating'></div> 

But it doesn't work. How can the icon be rotated using CSS?

like image 249
Alexander Ruliov Avatar asked Jun 20 '11 11:06

Alexander Ruliov


People also ask

How do I make infinite rotation in CSS?

To create an endless rotation animation simply define a @keyframe with any name and from and to values. Then you can use this @keyframe in your animation in any CSS class.

How do you rotate an animation in CSS?

To create a rotating animation in CSS, use the animation property and set the value of animations like duration, direction, and speed. Moreover, the rotate() CSS function is being used to rotate an element circularly in the transform property.

How do I spin an element in CSS?

The CSS rotate() function lets you rotate an element on a 2D axis. The rotate() function accepts one argument: the angle at which you want to rotate your web element. You can rotate an element clockwise or counter-clockwise.

How do I rotate an image 180 degrees CSS?

Rotating images in real-time with the rotate parameter To rotate the image by 180 degrees, we need to add rt-180 transformation parameter to the URL, as shown below. The resulting image is the same as passing 180deg to the rotate function in CSS.


2 Answers

@-webkit-keyframes rotating /* Safari and Chrome */ {    from {      -webkit-transform: rotate(0deg);      -o-transform: rotate(0deg);      transform: rotate(0deg);    }    to {      -webkit-transform: rotate(360deg);      -o-transform: rotate(360deg);      transform: rotate(360deg);    }  }  @keyframes rotating {    from {      -ms-transform: rotate(0deg);      -moz-transform: rotate(0deg);      -webkit-transform: rotate(0deg);      -o-transform: rotate(0deg);      transform: rotate(0deg);    }    to {      -ms-transform: rotate(360deg);      -moz-transform: rotate(360deg);      -webkit-transform: rotate(360deg);      -o-transform: rotate(360deg);      transform: rotate(360deg);    }  }  .rotating {    -webkit-animation: rotating 2s linear infinite;    -moz-animation: rotating 2s linear infinite;    -ms-animation: rotating 2s linear infinite;    -o-animation: rotating 2s linear infinite;    animation: rotating 2s linear infinite;  }
<div     class="rotating"    style="width: 100px; height: 100px; line-height: 100px; text-align: center;"    >Rotate</div>
like image 176
Kirk Strobeck Avatar answered Oct 05 '22 00:10

Kirk Strobeck


Working nice:

#test {      width: 11px;      height: 14px;      background: url('data:image/gif;base64,R0lGOD lhCwAOAMQfAP////7+/vj4+Hh4eHd3d/v7+/Dw8HV1dfLy8ubm5vX19e3t7fr 6+nl5edra2nZ2dnx8fMHBwYODg/b29np6eujo6JGRkeHh4eTk5LCwsN3d3dfX 13Jycp2dnevr6////yH5BAEAAB8ALAAAAAALAA4AAAVq4NFw1DNAX/o9imAsB tKpxKRd1+YEWUoIiUoiEWEAApIDMLGoRCyWiKThenkwDgeGMiggDLEXQkDoTh CKNLpQDgjeAsY7MHgECgx8YR8oHwNHfwADBACGh4EDA4iGAYAEBAcQIg0Dk gcEIQA7');  }    @-webkit-keyframes rotating {      from{          -webkit-transform: rotate(0deg);      }      to{          -webkit-transform: rotate(360deg);      }  }    .rotating {      -webkit-animation: rotating 2s linear infinite;  }
<div id='test' class='rotating'></div>
like image 34
Alexander Ruliov Avatar answered Oct 05 '22 00:10

Alexander Ruliov