html - 网页设计/CSS : Blurred text jitters when being "un-blurred" on hover

标签 html css hover transition blur

请看一下这个 jsfiddle:https://jsfiddle.net/heLwx9bz/

我正在尝试通过过渡“取消模糊”悬停时的一些文本。请注意在转换为 blur(0px) 时文本如何轻微抖动,它向上和向左跳动了大约 1px。为什么会这样,我该如何避免呢?只有在向属性更改添加过渡时才会发生抖动。

这是我的测试用例的代码,非常简单:

p {
  font-size: 200px;
}

.blur {
  filter: blur(2.5px);
  transition: 0.7s -webkit-filter;
}

.blur:hover {
  filter: blur(0px);
}
<div>
  <p class="blur">
    TEST
  </p>
</div>

最佳答案

这是 Google Chrome 的问题。

Certain css transitions will be hardware accelerated. What this means is that they will use the power of your computers graphics card to apply the transitions – and since the graphics card is optimized for graphical effects, this makes the transitions much smoother.

The thing is transitions don’t always use hardware acceleration, but if you apply a specific css rule then they will force it to enable. One of the css properties that will enable hardware acceleration is the transform rules. So apply a css transform and the graphics card does all the work.

只需在代码中添加 -webkit-transform: translateZ(0); 即可修复。

p {
  font-size: 200px;
}

.blur {
  filter: blur(2.5px);
  transition: 0.7s -webkit-filter;
  -webkit-transform: translateZ(0);
}

.blur:hover {
  filter: blur(0px);
}
<div>
  <p class="blur">
    TEST
  </p>
</div>

关于html - 网页设计/CSS : Blurred text jitters when being "un-blurred" on hover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47970803/

相关文章:

CSS如何让一个div在右边,一个div恰好在中间?

css - 浏览器只加载一种字体

html - Internet Explorer 运行不佳 - 网站左对齐且宽度不是 100%

html - 悬停在 <li> 上不起作用!

html - 将鼠标悬停在一个 div 上时更改所有其他 div 上的字体颜色

javascript - 如果值未更改,如何在提交时删除不需要的输入字段中的默认值?

javascript - 使用 jQuery 选择范围内的单选按钮值

javascript - 如何引用我的网站中的文档以独立于网站位置和使用位置

javascript - Bokeh :在悬停回调中更改圆圈大小

html - 设置 GitHub Pages 元素页面。页面打开但图像和 main.css 未加载