CSS 动画时间比例不正确

问题描述 投票:0回答:1

我正在尝试执行下面的动画,该动画基本上包括升起锁,使其旋转,然后下降。我希望这件事能按比例完成。然而,即使使用低得多的下降百分比,动画似乎也会在 2 秒内执行前两个步骤,并在剩余的 2 秒内执行下降。

@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
css animation rotation transform
1个回答
0
投票

我发现镜像动画很有帮助。这更接近您想要的吗?

@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%, 97% {
        transform: translatey(-4px);
    }

    97%, 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>

© www.soinside.com 2019 - 2024. All rights reserved.