[英]Weird glitch when scale and blur an image in chrome
I'm experimenting a "zoom and blur" css effect.我正在试验“缩放和模糊”css 效果。 So when I hover over an image, it's supposed to blur out and scale a bit, while contained in a div with
overflow:hidden
.因此,当我将鼠标悬停在图像上时,它应该会模糊并稍微缩放,同时包含在一个带有
overflow:hidden
的 div 中。
However, when running in Chrome, there's always a weird glitch.但是,在 Chrome 中运行时,总会出现一个奇怪的故障。 A blurry white border shows up around the container while the transition is going.
过渡进行时,容器周围会出现模糊的白色边框。
I'm wondering if there's a better way of doing it?我想知道是否有更好的方法来做到这一点? Or a method of circumventing it?
或者有什么方法可以绕过? Thanks a lot!
非常感谢!
You can see a gif demonstrating the problem: http://imgur.com/SrK5rXq您可以看到演示问题的 gif: http : //imgur.com/SrK5rXq
And the same code running in firefox as a comparison: http://imgur.com/942LBKV和在 Firefox 中运行的相同代码作为比较: http : //imgur.com/942LBKV
Note the borders within the image.注意图像中的边框。
And below is my code:下面是我的代码:
<style>
#img0{
width:500px;
height:auto;
}
.hoverBlur{
-webkit-transition:all 0.5s ease;
-moz-transition:all 0.5s ease;
}
.hoverBlur:hover{
-webkit-transform:scale(1.1);
-moz-transform:scale(1.1);
transform:scale(1.1);
-webkit-filter:blur(15px);
-moz-filter:blur(15px);
filter:blur(15px);
}
.container{
margin:200px;
width:500px;
height:333px;
border:1px solid #ccc;
overflow:hidden;
}
</style>
<div class="container">
<img id="img0" src="test.jpg" class="hoverBlur"/>
</div>
This is a REALLY old thread but I ran into this issue and couldn't find the solution published anywhere else so I'm posting it here:这是一个非常古老的线程,但我遇到了这个问题,并不能找到其他地方发表过,所以我在这里张贴的解决方案:
You can fix this by adding a margin to the image that is the same size as the blur size (in this case 15px) then transform: translating the image back into place.您可以通过向图像添加与模糊大小相同的边距(在本例中为 15 像素)来解决此问题,然后转换:将图像转换回原位。
https://jsfiddle.net/zeojxtvb/ https://jsfiddle.net/zeojxtvb/
So in our example, a blur(15px) is applied to the image.因此,在我们的示例中,对图像应用了模糊 (15px)。 So also apply the following to the image:
因此,还将以下内容应用于图像:
img {
...
margin: 15px;
transform: translate(-15px, -15px);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.