我想使用悬停效果,例如 this tutorial 中的悬停效果,但令我沮丧的是,效果无法响应。正如您将在这些屏幕截图中看到的那样,在不同的缩放级别和 Firefox 中也存在问题。 (说明问题的 Here is a codepen)。
在 Chrome 中 100% 缩放:
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>
关于html - 跨浏览器/缩放响应悬停效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32702816/