html - 使文本显示在悬停和模糊效果闪烁修复

标签 html css css-transitions css-filters

/* 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/

相关文章:

css - Bootstrap 导航栏菜单中的悬停过渡

javascript - 每次单击按钮时 CSS 递增过渡动画

javascript - Youtube iframe 视频通过单个按钮播放/静音。单击播放/静音时还可切换图像

javascript - 如果我声明 CSS 中的 id 与 Javascript 中的 id 重复,会发生什么情况?

JQuery 在静态 HTML 页面中搜索并突出显示找到的单词

php - HTML。表单成功完成后如何停止重定向?

android - 覆盖图像 mask 不适用于 Motorola Xoom (android 4.0.4)

css - 径向渐变背景未正确过渡

php - 使用 MYSQL 和 PHP 以 HTML 形式进行搜索

css - IE7 错误 - span 覆盖了链接