【问题标题】:Making text show up on hover and blur effect blinking fix使文本显示在悬停和模糊效果闪烁修复
【发布时间】:2016-05-10 17:02:57
【问题描述】:

/* 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 中看起来“不稳定”。奇怪的。不过在Mozilla中完全没问题,至少如果你在-webkit-filter之后添加filter...无论如何,要使文本出现,请在过滤器后的范围内添加文本,绝对定位,使用@使其不可见987654325@ 并使用img:hover + span 选择器来显示它。
  • 如何让它在 Firefox 中工作?我刚刚在 Firefox 中尝试了我的代码,但它甚至都不起作用大声笑

标签: html css css-transitions css-filters


【解决方案1】:

编辑:现在在 Chrome 中看起来很棒

我认为使用 webkit blur 时完全不可能获得超级干净的过渡。我以前使用它时遇到过很多渲染问题和故障。当用于许多元素时,它也是一种资源消耗。我的建议是将您的缓动更改为线性并仅针对模糊。那应该收紧一点。

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; 的元素。初始 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

【讨论】:

  • 能否也为 Firefox 添加代码(filter 不带前缀等)。
  • 已添加 Firefox 过滤器
  • Firefox 模糊没有 0.5 秒的“过渡”时间。其余的都可以,谢谢
  • 谢谢!将其设为linear 即可消除闪烁。
猜你喜欢
  • 2013-06-07
  • 2017-10-14
  • 1970-01-01
  • 2016-05-30
  • 1970-01-01
  • 2021-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多