这是下面屏幕截图中圆形标志图标的问题。我希望它顺时针旋转 45 度并保持它以 + 形状旋转,只要光标悬停在图像上;然后在光标离开图像时向后逆时针旋转。
这是我到目前为止编写的代码。悬停时,图像正确旋转 45' cw,但它会立即返回 X 形状。
#icon{
display: inline-block;
margin: 0 auto 0 0;
width: 2.4em;
height: 2.4em;
}
#icon:hover{
-webkit-animation:cw 0.4s linear 1;
-moz-animation:cw 0.4s linear 1;
animation:cw 0.4s linear 1;
}
@-moz-keyframes cw { 100% { -moz-transform: rotate(45deg); } }
@-webkit-keyframes cw { 100% { -webkit-transform: rotate(45deg); } }
@keyframes cw { 100% { -webkit-transform: rotate(45deg); transform:rotate(45deg); } }
@-moz-keyframes ccw { 100% { -moz-transform: rotate(-45deg); } }
@-webkit-keyframes ccw { 100% { -webkit-transform: rotate(-45deg); } }
@keyframes ccw { 100% { -webkit-transform: rotate(-45deg); transform:rotate(-45deg); } }
那么我该如何解决这个问题呢?我认为#icon
应该稍微修改一下,因为即使在旋转后它也可能保持其原始状态。
使用 atransition
而不是keyframes
动画:
img {
transition: all .2s ease;
transform: rotate(0deg)
}
img:hover {
transform: rotate(45deg)
}
<img src="https://placehold.it/100x100">
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句