div无法顺利进出脉冲动画?
https://jsfiddle.net/86gxLy2a/
CSS
div {
width: 20px;
height: 20px;
border-radius: 10px;
border: 2px solid black;
transform: scale(.5);
transition: all .3s ease-in-out;
}
div:hover {
animation: pulse 1s infinite;
}
@keyframes pulse {
from, to {
transform: scale(1);
}
50% {
transform: scale(.8);
}
}
答案 0 :(得分:2)
您可以延迟动画并在悬停时放大
更新:现在也可以在Chrome中顺利运行。现在唯一的问题是,脉冲动画将在页面加载时运行。
div {
width: 20px;
height: 20px;
border-radius: 10px;
border: 2px solid black;
-webkit-transform: scale(.5);
-moz-transform: scale(.5);
-ms-transform: scale(.5);
-o-transform: scale(.5);
transform: scale(.5);
transition: all .3s ease-in-out;
animation: unpulse .3s;
}
div:hover {
transform: scale(1);
animation: pulse 1s infinite;
animation-delay: .3s;
}
@keyframes pulse {
to {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(.8);
-moz-transform: scale(.8);
-ms-transform: scale(.8);
-o-transform: scale(.8);
transform: scale(.8);
}
}
@keyframes unpulse {
0% {
-webkit-transform: scale(.9);
-moz-transform: scale(.9);
-ms-transform: scale(.9);
-o-transform: scale(.9);
transform: scale(.9);
}
100% {
-webkit-transform: scale(.5);
-moz-transform: scale(.5);
-ms-transform: scale(.5);
-o-transform: scale(.5);
transform: scale(.5);
}
}
<div>
</div>
答案 1 :(得分:0)
你的div的比例需要等于动画的初始比例才能显得平滑
变换:scale(1); - DIV
变换:scale(1); - 动画第一个关键帧
div {
width: 20px;
height: 20px;
border-radius: 10px;
border: 2px solid black;
transform: scale(1);
transition: all .3s ease-in-out;
}
div:hover {
animation: pulse 1s infinite;
}
@keyframes pulse {
from, to {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
}
50% {
-webkit-transform: scale(.8);
-moz-transform: scale(.8);
-ms-transform: scale(.8);
-o-transform: scale(.8);
transform: scale(.8);
}
}
&#13;
<div>
</div>
&#13;