【发布时间】:2021-01-22 07:35:03
【问题描述】:
所以我的目标是让两个圆圈从屏幕的两侧相遇并在中间相遇以执行动画的后半部分(缩放和不透明度变化)。
但是通过设置初始关键帧和最后使用 vw 他们不会在中间相遇 - 因为 vw 值是相对于 div 的左侧而不是中心(我使用 vw 因为我需要这个响应)。所以,会发生什么是圆的左侧在中心相遇。
有没有人知道只使用 css 的简单解决方法?我对编码很陌生,所以如果答案很明显,我很抱歉。
这是我的代码:
@keyframes left {
0% {
transform: translate3d(0vw, 50%, 0) scale3d(1, 1, 1);
opacity: 50%;
animation-timing-function: ease-in;
}
60% {
transform: translate3d(50vw, 50%, 0) scale3d(1, 1, 1);
opacity: 50%;
animation-timing-function: ease-out;
}
100% {
transform: translate3d(50vw, 50%, 0) scale3d(2, 2, 1);
opacity: 0%;
animation-timing-function: ease-out;
}
}
@keyframes right {
0% {
transform: translate3d(100vw, 50%, 0) scale3d(1, 1, 1);
opacity: 50%;
animation-timing-function: ease-in;
}
60% {
transform: translate3d(50vw, 50%, 0) scale3d(1, 1, 1);
opacity: 50%;
animation-timing-function: ease-out;
}
100% {
transform: translate3d(50vw, 50%, 0) scale3d(2, 2, 1);
opacity: 0%;
animation-timing-function: ease-out;
}
}
.circleleft {
overflow: hidden;
position: absolute;
background: white;
border-radius: 50%;
width: 500px;
height: 500px;
animation: left 2s;
animation-fill-mode: forwards;
}
.circleright {
overflow: hidden;
position: absolute;
background: white;
border-radius: 50%;
width: 500px;
height: 500px;
animation: right 2s;
animation-fill-mode: forwards;
}
<div style="width:100vw; height:100vh; background-color:#87827E">
<div class="circleleft"></div>
<div class="circleright"></div>
</div>
您也可以在这里看到它的使用情况:https://ruairimadine.co.uk/sudoroux
【问题讨论】:
标签: html css css-animations keyframe translate3d