Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css rotation without pausing

I have this little image that I want to rotate continuously or at least have a shorter break between animations.

Here's a gif of the behaviour (it's a bit ugly because of my gif-record-software, but the pause is the thing I wish to highlight here):

enter image description here

My css (less):

.add{
vertical-align: middle;
    line-height: 35px;
    display: inline-block;
    margin-top: 8px;
    margin-left:5px;
    svg{
        fill:@colorOnBright;
        max-width: 30px;
        max-height: 25px;
        vertical-align: middle;
    }
}

.animated {
  animation-name: rotation;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-timing-function: ease;
}

@keyframes rotation {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(359deg);
  }
}

markup:

<svg class="add animated" click.delegate="Add()">
     <use xlink:href="#add"></use>
</svg>

So, how do I get rid of the pause? or alternatively make the pause shorter.

Thanks in advance.

EDIT: I can't make sense of this.. I've tried recreating the thing in a pen, and it works just fine. Is there some other css-property that interferes with the animation somehow?

https://codepen.io/litari/pen/ajdpjp

edit2: If I inspect and view the animations, I get this: enter image description here

So it goes from 0 to 360 degrees at 25% and for the remaining 75% it just stays at 360deg.

like image 694
Johan Hjalmarsson Avatar asked Dec 17 '25 12:12

Johan Hjalmarsson


2 Answers

If I understand you correctly, replace:

.animated {
  animation-timing-function: ease;
}

with:

.animated {
  animation-timing-function: linear;
}

The linear timing-function value maintains the same speed throughout the animation.

https://www.smashingmagazine.com/2014/04/understanding-css-timing-functions/#linear

div {
  display: inline-block;
}

.animated {
  animation-name: rotation;
  animation-duration: 2s;
  animation-iteration-count: infinite;
  animation-timing-function: ease;
  transform-origin: center;
}

@keyframes rotation {
  from {
    -webkit-transform: rotate(0deg);
  }
  to {
    -webkit-transform: rotate(359deg);
  }
}

.linear {
  animation-timing-function: linear;
}
<div class="animated">+</div>
<p>and with linear:</p>
<div class="animated linear">+</div>
like image 76
Mosh Feu Avatar answered Dec 19 '25 05:12

Mosh Feu


Setting animation-timing-function: linear and -webkit-transform: rotate(360deg) works fine

        .animated {
          width: 50px;
          height: 50px;
          border-radius: 50%;
          background: black;
          animation-name: rotation;
          animation-duration: 2s;
          animation-iteration-count: infinite;
          animation-timing-function: linear;
        }
        
        @keyframes rotation {
          from {
            -webkit-transform: rotate(0deg);
          }
          to {
            -webkit-transform: rotate(360deg);
          }
        }
         
        .ball{
      width: 20px;
      height: 20px;
      background: red;
      border-radius: 50%;
         }
        
        
        <div class="animated">
          <div class="ball"></div>
        </div>
        
like image 34
Friday Ameh Avatar answered Dec 19 '25 06:12

Friday Ameh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!