vla*_*lad 14 animation css3 css-transitions css-animations
我有一个具有无限css3动画的元素,当元素悬停时,它会被更改为另一个无限动画.一切都还可以,但有时动画变化过于有弹性,有没有办法让动画在动画之间平滑(可能在动画之间将元素带到初始状态)在mouseenter和mouseleave上?两个动画的开始和结束状态是相同的.
@keyframes first-animation {
0% { transform: scale3d(1,1,0);}
50% { transform: scale3d(0.8,0.8,0); }
100% { transform: scale3d(1,1,0); }
};
@keyframes second-animation {
0% { transform: scale3d(1,1,0); }
70% { transform: scale3d(0.7,0.7,0); }
80% { transform: scale3d(0.9,0.9,0); }
100% { transform: scale3d(1,1,0); }
};
div{
animation: first-animation 1.7s ease-in-out infinite;
}
div:hover, div:focus{
animation: second-animation 1.1s ease-in-out infinite;
}
Run Code Online (Sandbox Code Playgroud)
我不认为可以使用比例变换来实现.
你可以做一个技巧并从scale()更改为translateZ().应用透视时,净效果也将是一个比例.但有趣的一点是,将视角设置为高值,这种尺度效应可以做得非常小.透视是一种可动画的属性.
缺点是我们需要添加2个环绕层...但最终结果是这样.我保留了原始版本进行比较
@keyframes first-animation {
0% { transform: scale(1,1);}
50% { transform: scale(0.8,0.8); }
100% { transform: scale(1,1); }
}
@keyframes second-animation {
0% { transform: scale(1,1); }
70% { transform: scale(0.7,0.7); }
80% { transform: scale(0.9,0.9); }
100% { transform: scale(1,1); }
}
.sample {
background-color: lightblue;
animation: first-animation 1.7s ease-in-out infinite;
}
.sample:hover {
animation: second-animation 1.1s ease-in-out infinite;
}
.dim {
width: 200px;
height: 200px;
}
.base1 {
perspective: 1000px;
transition: perspective 2s ease-out;
position: absolute;
left: 300px;
top: 10px;
}
.base1:hover {
perspective: 9999px;
}
.base2 {
width: 100%;
height: 100%;
animation: animation1 1.7s ease-in-out infinite;
perspective: 9999px;
transition: perspective 2s ease-in;
}
.base1:hover .base2 {
perspective: 1000px;
}
.inner {
width: 100%;
height: 100%;
background-color: lightgreen;
animation: animation2 1.1s ease-in-out infinite;
transform-style: preserve-3d;
perspective: 99999px;
}
@keyframes animation1 {
0% { transform: translateZ(0px);}
50% { transform: translateZ(-200px); }
100% { transform: translateZ(0px); }
}
@keyframes animation2 {
0% { transform: translateZ(0px);}
70% { transform: translateZ(-300px); }
80% { transform: translateZ(-100px); }
100% { transform: translateZ(0px); }
}
Run Code Online (Sandbox Code Playgroud)
<div class="sample dim">SAMPLE</div>
<div class="base1 dim">
<div class="base2">
<div class="inner">DEMO</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4038 次 |
最近记录: |