Pure CSS rotate animation broken while in infinite loop

前端 未结 2 1438
借酒劲吻你
借酒劲吻你 2021-01-14 02:26

It\'s been a while since I asked a question here. So excuse me if I do anything wrong.

I have an issue with CSS animation. I would like my animation

2条回答
  •  生来不讨喜
    2021-01-14 03:02

    A similar problem has already been described on SO: How to have the object not revert to its initial position after animation has run? The problem is that at the beginning of the animation, the object returns to its original state. But I solved the problem differently: I simply combined both animations into one, and now both reversals are described by one function. If you definitely need both animations, then redo it, as stated in the question I've given link to. Here is my code:

    #loader {
      width: 240px;
      height: 100px;
    }
    
    .inner {
      position: relative;
      width: 100%;
      height: 100%;
      text-align: center;
      transition: transform 2s;
      transform-style: preserve-3d;
      background-color: transparent;
    }
    
    .front,
    .back {
      position: absolute;
      width: 80px;
      height: 50px;
      backface-visibility: hidden;
    }
    
    #loader1 {
      float: left;
      width: 80px;
      height: 50px;
      perspective: 1000px;
      background-color: transparent;
    }
    
    #loader1 .inner {
      animation: spin 20s ease 0s infinite;
      -webkit-animation: spin 20s ease 0s infinite;
    }
    
    #loader1 .front {
      background-color: #db9834;
    }
    
    #loader1 .back {
      background-color: #3498db;
      transform: rotateY(180deg);
    }
    
    /* -------------------------------------------------------- */
    
    #loader2 {
      float: left;
      width: 80px;
      height: 50px;
      perspective: 1000px;
      background-color: transparent;
    }
    
    #loader2 .inner {
      animation: spin 20s ease 1s infinite;
      -webkit-animation: spin 20s ease 1s infinite;
    }
    
    #loader2 .front {
      background-color: #db8834;
    }
    
    #loader2 .back {
      background-color: #3488db;
      transform: rotateY(180deg);
    }
    
    
    /* -------------------------------------------------------- */
    
    #loader3 {
      float: left;
      width: 80px;
      height: 50px;
      perspective: 1000px;
      background-color: transparent;
    }
    
    #loader3 .inner {
      animation: spin 20s ease 2s infinite;
      -webkit-animation: spin 20s ease 2s infinite;
    }
    
    #loader3 .front {
      background-color: #db7834;
    }
    
    #loader3 .back {
      background-color: #3478db;
      transform: rotateY(180deg);
    }
    
    
    /* -------------------------------------------------------- */
    
    #loader4 {
      float: left;
      width: 80px;
      height: 50px;
      perspective: 1000px;
      background-color: transparent;
    }
    
    #loader4 .inner {
      animation: spin 20s ease 3s infinite;
      -webkit-animation: spin 20s ease 3s infinite;
    }
    
    #loader4 .front {
      background-color: #db6834;
    }
    
    #loader4 .back {
      background-color: #3468db;
      transform: rotateY(180deg);
    }
    
    
    /* -------------------------------------------------------- */
    
    #loader5 {
      float: left;
      width: 80px;
      height: 50px;
      perspective: 1000px;
      background-color: transparent;
    }
    
    #loader5 .inner{ 
      animation: spin 20s ease 4s infinite;
      -webkit-animation: spin 20s ease 4s infinite;
    }
    
    #loader5 .front {
      background-color: #db5834;
    }
    
    #loader5 .back {
      background-color: #3458db;
      transform: rotateY(180deg);
    }
    
    
    /* -------------------------------------------------------- */
    
    #loader6 {
      float: left;
      width: 80px;
      height: 50px;
      perspective: 1000px;
      background-color: transparent;
    }
    
    #loader6 .inner {
      animation: spin 20s ease 5s infinite;
      -webkit-animation: spin 20s ease 5s infinite;
    }
    
    #loader6 .front {
      background-color: #db4834;
    }
    
    #loader6 .back {
      background-color: #3448db;
      transform: rotateY(180deg);
    }
    
    
    @-webkit-keyframes spin {
      0% {
        -webkit-transform: rotateY(0deg);
      }
      8% {
        -webkit-transform: rotateY(180deg);
      }
      50% {
        -webkit-transform: rotateY(180deg);
      }
      
      58% {
        -webkit-transform: rotateY(0deg);
      }
      
      100% {
        -webkit-transform: rotateY(0deg);
      }
    }
    
    @keyframes spin {
      0% {
        -webkit-transform: rotateY(0deg);
      }
      8% {
        -webkit-transform: rotateY(180deg);
      }
      50% {
        -webkit-transform: rotateY(180deg);
      }
      
      58% {
        -webkit-transform: rotateY(0deg);
      }
      
      100% {
        -webkit-transform: rotateY(0deg);
      }
    }

提交回复
热议问题