我想使用悬停效果,例如this tutorial中的效果,但令我沮丧的是,该效果无法响应。如这些屏幕截图所示,在不同的缩放级别和Firefox中也存在问题。 (说明问题的Here is a codepen)。
100%放大Chrome:
90%的Chrome:
在Firefox中,效果根本不起作用。
在Chrome中悬停时(旋转虚线):
在Firefox中悬停时(无虚线):
如何获得效果以响应方式工作?跨浏览器和不同缩放级别。
以下是一些说明该方法的代码段:
<div class="hi-icon-wrap hi-icon-effect-4 hi-icon-effect-4b">
<a href="#set-4" class="column product hi-icon product-icon"><div class="icon-text">Product</div></a>
</div>
CSS:
.hi-icon-effect-4b .hi-icon:hover {
-webkit-transition: box-shadow 0.2s;
-moz-transition: box-shadow 0.2s;
transition: box-shadow 0.2s;
}
.hi-icon-effect-4b .hi-icon:hover:after {
-webkit-animation: spinAround 9s linear infinite;
-moz-animation: spinAround 9s linear infinite;
animation: spinAround 9s linear infinite;
}
@-webkit-keyframes spinAround {
from {
-webkit-transform: rotate(0deg)
}
to {
-webkit-transform: rotate(360deg);
}
}
@-moz-keyframes spinAround {
from {
-moz-transform: rotate(0deg)
}
to {
-moz-transform: rotate(360deg);
}
}
@keyframes spinAround {
from {
transform: rotate(0deg)
}
to {
transform: rotate(360deg);
}
}
玩codepen here。感谢您的想法!
最佳答案
这是解决问题的一种尝试。
我避免使用边框,而使用背景处理所有内容:一些用于条纹,另一种用于隐藏显示效果,另一种用于遮盖内部圆圈。
现在它可以响应了(边框的大小是填充,可以设置为百分比),并且在FF中可以正常工作。
背景具有不同的颜色,因此很容易看到每个背景,并且旋转也会延迟,从而更容易看到正在发生的情况
但是现在在IE中失败了。
希望有人可以解决这个问题
.hi-icon {
width: 100px;
height: 100px;
position: relative;
font-size: 50px;
padding: 50px;
border-radius: 50%;
}
.hi-icon:after {
content: "";
position: absolute;
left: 0px;
top: 0px;
right: 0px;
bottom: 0px;
padding: 3%;
border-radius: 50%;
background-image: linear-gradient(lightgray, lightgray),
linear-gradient(transparent 30%, red 70%),
linear-gradient(45deg, blue 0%, blue 25%, transparent 25%, transparent 50%, blue 50%, blue 75%, transparent 75%, transparent 100%),
linear-gradient(-45deg, green 0%, green 25%, transparent 25%, transparent 50%, green 50%, green 75%, transparent 75%, transparent 100%),
linear-gradient(225deg, blue 0%, blue 25%, transparent 25%, transparent 50%, blue 50%, blue 75%, transparent 75%, transparent 100%),
linear-gradient(135deg, blue 0%, blue 25%, transparent 25%, transparent 50%, blue 50%, blue 75%, transparent 75%, transparent 100%);
background-position: center center,bottom center,top left,bottom left,bottom right,top right;
background-size: 100% 100%,100% 1000%,50% 50%,50% 50%,50% 50%,50% 50%;
background-clip: content-box,border-box,border-box,border-box,border-box,border-box;
background-repeat:no-repeat;
transition: background-position 1s;
z-index: -1;
}
.hi-icon:hover:after {
background-position: center center,top center,top left,bottom left,bottom right,top right;
animation: rotate 3s linear infinite 1s;
}
@keyframes rotate {
0% {transform: rotate(0deg);}
100% {transform: rotate(360deg);}
}
<div class="hi-icon">TEST</div>