/* CSS used here will be applied after bootstrap.css */
body{
background-color:yellow;
}
img{
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
transition: all 0.5s ease;
}
img:hover{
-webkit-filter:blur(5px);
}
<img src="http://i.stack.imgur.com/K0jNI.png">
当您将鼠标悬停在图像上时,图像的边界会在稳定之前闪烁一下。有没有办法解决这个问题?
当我将鼠标悬停在图片上时,如何让文字显示在图片中间?
最佳答案
编辑:这在 Chrome 中看起来很棒
我认为在使用 webkit blur 时完全不可能获得 super 干净的过渡。我以前使用它时遇到过很多渲染问题和故障。当用于很多元素时,它也是一种资源消耗。我的建议是将您的缓动更改为线性并仅针对模糊。这应该会收紧一点。
img{
-webkit-transition: -webkit-filter 0.5s linear;
-moz-transition: -webkit-filter 0.5s linear;
-o-transition: -webkit-filter 0.5s linear;
-ms-transition: -webkit-filter 0.5s linear;
transition: -webkit-filter 0.5s linear;
}
至于文本淡入。您需要添加一个元素,该元素最初是 opacity:0;
但随后更改为 opacity:1;
当父 block 悬停。初始 HTML 更改为:
<div class='block'>
<img src="https://www.nasa.gov/sites/default/files/styles/image_card_4x3_ratio/public/thumbnails/image/leisa_christmas_false_color.png?itok=Jxf0IlS4">
<span>Hey there</span>
</div>
和新的 CSS
/* CSS used here will be applied after bootstrap.css */
body {
background-color: yellow;
}
img {
-webkit-transition: -webkit-filter 0.5s linear;
transition: -webkit-filter 0.5s linear;
}
.block {
position: relative;
width: 400px;
}
.block img {
width: 100%;
}
.block span {
opacity: 0;
-webkit-transition: all .3s;
transition: all .3s;
color: white;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
text-align: center;
left: 0;
right: 0;
}
.block:hover > span {
opacity: 1;
}
img:hover {
-webkit-filter: blur(4px);
}
例子在这里
http://codepen.io/jcoulterdesign/pen/58d613e80e4a768cc9e54aa1e7aaa0af
关于html - 使文本显示在悬停和模糊效果闪烁修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37144769/