skip to Main Content

I’m trying to execute the animation below, which basically consists of raising the lock, making it rotate and then going down. I would like this to be done proportionately. However, even using a much lower percentage for the descent, the animation seems to execute the first two steps in 2s and the descent in the remaining 2s.

@keyframes float {
    0%,3% {

        transform: translatey(0px);
    }
    3%, 6% {

        transform: translatey(-4px);
    }
    
    6%, 30%{
        transform: rotateY(0deg) translatey(-4px);
    }
    30%, 94%{
        transform: rotateY(1080deg) translatey(-4px);
    }

    94%, 100%{
        transform: translatey(0px);
    }
}

.square {
    
    animation: float linear infinite;
    animation-duration: 4s;
}

div {
    perspective: 500px; 
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 44px;
}

.cadeado{
    background-image: url(https://www.qas.flyembraer.com/irj/go/km/docs/download_center/Anonymous/loading-sem-cadeado.jpg);
    width: 144px;
    height: 144px;
    align:center;
}
<div class="cadeado">
<div class ="square"><img src="https://www.qas.flyembraer.com/irj/go/km/docs/download_center/Anonymous/cadeado.jpg" alt="" align="center"></div>
</div>

I've tried setting the proportional % to 33% for each step but it still doesn't work

2

Answers


  1. I have found that mirroring he animation to be helpful. Is this closer to what you were looking for?

    @keyframes float {
        0%,10% {
    
            transform: translatey(0px);
        }
        10%, 20% {
    
            transform: translatey(-4px);
        }
        
        20%, 60%{
            transform: rotateY(0deg) translatey(-4px);
        }
        60%, 80%{
            transform: rotateY(1080deg) translatey(-4px);
        }
        80%, 90% {
            transform: translatey(-4px);
        }
    
        90%, 100%{
            transform: translatey(0px);
        }
    }
    
    .square {
        
        animation: float linear infinite;
        animation-duration: 5s;
    }
    
    div {
        perspective: 500px; 
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 44px;
    }
    
    .cadeado{
        background-image: url(https://www.qas.flyembraer.com/irj/go/km/docs/download_center/Anonymous/loading-sem-cadeado.jpg);
        width: 144px;
        height: 144px;
        align:center;
    }
    <div class="cadeado">
    <div class ="square"><img src="https://www.qas.flyembraer.com/irj/go/km/docs/download_center/Anonymous/cadeado.jpg" alt="" align="center"></div>
    </div>
    Login or Signup to reply.
  2. @keyframes float {
      0%,
      8.33% {
        transform: translateY(0px) rotateY(0deg);
      }
      8.33%,
      50% {
        transform: translateY(-30px) rotateY(0deg);
      }
      50%,
      83.33% {
        transform: translateY(-30px) rotateY(1080deg);
      }
      83.33%,
      100% {
        transform: translateY(0px) rotateY(1080deg);
      }
    }
    
    .square {
      animation: float 4s linear infinite;
    }
    
     div {
       perspective: 500px; 
       display: flex;
       justify-content: center;
       align-items: center;
       margin-bottom: 44px;
    }
    
       .cadeado{
       background-image: url(https://www.qas.flyembraer.com/irj/go/km/docs/download_center/Anonymous/loading-sem-cadeado.jpg);
    width: 144px;
    height: 144px;
    align:center;
       }
    <div class="cadeado">
    <div class ="square"><img src="https://www.qas.flyembraer.com/irj/go/km/docs/download_center/Anonymous/cadeado.jpg" alt="" align="center"></div>
    </div>

    These timings somewhat matches your query. For the first 0.5s the lock moves -30px upwards, then rotates for 3s and then moves back to original position in 0.5s. So a total 4s animation.

    @keyframes float {
      0%,
      8.33% {
        transform: translateY(0px) rotateY(0deg);
      }
      8.33%,
      50% {
        transform: translateY(-30px) rotateY(0deg);
      }
      50%,
      83.33% {
        transform: translateY(-30px) rotateY(1080deg);
      }
      83.33%,
      100% {
        transform: translateY(0px) rotateY(1080deg);
      }
    }
    
    .square {
      animation: float 4s linear infinite;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search