15

Everything works good on Firefox but chrome shows the animated text blurry. I did everything like -webkit-font-smoothing: subpixel-antialiased; , -webkit-transform: translate3d(0,0,0); and everything mentioned here before:

Webkit-based blurry/distorted text post-animation via translate3d

but the problem still exist.

I made very simple example to show you how it looks like. How can I fix this problem?

var text = 1;

function next() {

  var next = (text == 2) ? 1 : 2;
  document.getElementById('text' + text).className = 'out';
  document.getElementById('text' + next).className = 'in';
  text = next;
}
body {
  padding: 0;
  margin: 0;
  font-family: tahoma;
  font-size: 8pt;
  color: black;
}
div {
  height: 30px;
  width: 100%;
  position: relative;
  overflow: hidden;
  margin-bottom: 10px;
}
div div {
  opacity: 0;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
}
.in {
  -webkit-animation: comein 1s 1;
  -moz-animation: comein 1s 1;
  animation: comein 1s 1;
  animation-fill-mode: both;
}
@keyframes comein {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
.out {
  -webkit-animation: goout 1s 1;
  -moz-animation: goout 1s 1;
  animation: goout 1s 1;
  animation-fill-mode: both;
}
@keyframes goout {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
<div>
  <div class="in" id="text1">Hello! I'm Test Text. I'm Test Text jr Father!</div>
  <div id="text2">Hi, I'm test text jr. I'm sharp and beautiful by nature but when I came in, Chrome made me blurry and I'm bad, I'm bad! ... Who's bad :)</div>
</div>

<button onclick="next();">Next</button>

You can also see the example at CodePen

10
  • 1
    Can't reproduce on Chrome v53: jsfiddle.net/1x8azozx
    – nkmol
    Oct 13, 2016 at 7:34
  • 1
    @nkmol you can try it with codepen: codepen.io/anon/pen/kkpJaL
    – ICE
    Oct 13, 2016 at 7:53
  • 1
    I am on chrome using OSX no blurryness here FYI Oct 13, 2016 at 8:21
  • 1
    @Mathijs Segers I don't have Mac but tested on Linux and Windows. Both have the same problem. I don't think it's about OS. It's about how Chrome handling animation. I really appreciate if you check this again on OSX again. I put the same text with and without animation to compare: codepen.io/anon/pen/kkpJaL
    – ICE
    Oct 13, 2016 at 8:53
  • 1
    @MathijsSegers Thanks. It must be something to get it fixed on Linux and Windows.
    – ICE
    Oct 13, 2016 at 11:14

5 Answers 5

10
+25

Update 2020-10: this issue appears to be resolved in Chrome/Chromium 85+ in my testing. But it is not entirely fixed. You may still encounter blur in places.

Check this comment in the bug report that outlines continuing work to improve how Chrome handles this: https://bugs.chromium.org/p/chromium/issues/detail?id=521364#c103

3
  • hmm I downloaded chrome canary (maybe not the same at chrome 72??) but I'm still seeing the text blur. My animation is different than the question above though. I am using transform: scale(1.02) so maybe there is a difference?
    – Sarah
    Jan 3, 2019 at 21:27
  • @ICE - can you post an example answer? I'm curious where you're still seeing issues. This site I built (live-nacubo-emp.pantheonsite.io) has the effect going down the green bar in the center of the screen and it looks pretty good now.
    – serraosays
    Nov 3, 2019 at 15:54
  • 1
    @ICE - if you blow the font size up in your example, there is little to no blur between the transitions. Your use case also appears much improved over what it was, even if it's not 100% fixed.
    – serraosays
    Nov 3, 2019 at 21:30
5

This misrendering often appears. You can try transform: translate3d(0, 0, 0) or transform: translateZ(0) und the element with the animation, but it doesnt works always.
-webkit-font-smoothing: antialised is another option but that never worked for me.

1
  • Thanks but I already mentioned on my question it can't solve the problem.
    – ICE
    Oct 16, 2016 at 8:43
0

When the animation is being moved using percentage the text will become blurred due to the the browser guessing its exact location during the repaint phases. Using a different unit to move in such as 'px' will allow the browser to be specific during it's repaint phase and allow the text to be clean and smooth.

After reading the below I realized that this same concept may also have a factor when it comes to the blurry effect on the text.

Percentages are relative values, which means they have to depend on some other value in order to produce result. So every time you assign a percentage value it has to get it's relative value to perform a calculation. When doing a translation with pixels you only have to change the translation values, but with percentages you have to get element's dimensions first and then apply the translation. And that has to be done for every animation frame.

You can read more about this here: https://stackoverflow.com/a/50416761/4518455

In my testings this seems to fix the issue fully for all of my animations in my application. (10+)

2
  • Thanks for you answer. I don't know about your case, but if you see the example I provided in question, you can find there isn't any percentage for positioning the text. even if we use div { width: 800px;, we still have the blur problem. I asked this question about 3 years ago and still Chrome didn't fix this problem while Firefox never had this problem.
    – ICE
    Jul 26, 2019 at 20:30
  • I should also mention, I have a hack to completely solve this problem but I think it can cause messy CSS. In my example create a class .show{opacity:1;} which is the exact thing for 100% animation value. now in JavaScript, instead of .className = 'in'; use .className = 'in show';. Now Chrome can release the animation at the end. Very weird but it works.
    – ICE
    Jul 26, 2019 at 20:32
0

The best solution for text blurring when adding an animation is add "z-index: 1;" on the style where animation is placed.

.in {
  -webkit-animation: comein 0.5s 1;
  -moz-animation: comein 0.5s 1;
  animation: comein 0.5s 1;
  animation-fill-mode: both;
  z-index: 1;
}
1
  • Still see the blur. Didn't fix the problem.
    – ICE
    Aug 26, 2019 at 8:44
-1

you can check this link its animation time issue pls check down link

var text = 1;

function next() {

  var next = (text == 2) ? 1 : 2;
  document.getElementById('text' + text).className = 'out';
  document.getElementById('text' + next).className = 'in';
  text = next;
}
body {
  padding: 0;
  margin: 0;
  font-family: tahoma;
  font-size: 8pt;
  color: black;
}
div {
  height: 30px;
  width: 100%;
  position: relative;
  overflow: hidden;
  margin-bottom: 10px;
}
div div {
  opacity: 0;
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
}
.in {
  -webkit-animation: comein 0.5s 1;
  -moz-animation: comein 0.5s 1;
  animation: comein 0.5s 1;
  animation-fill-mode: both;
}
@keyframes comein {
  0% {
    opacity: 0;
  }
 
  100% {
    opacity: 1;
  }
}
.out {
  -webkit-animation: goout 0.5s 1;
  -moz-animation: goout 0.5s 1;
  animation: goout 0.5s 1;
  animation-fill-mode: both;
}
@keyframes goout {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
<div>
  <div class="in" id="text1">Hello! I'm Test Text. I'm Test Text jr Father!</div>
  <div id="text2">Hi, I'm test text jr. I'm sharp and beautiful by nature but when I came in, Chrome made me blurry and I'm bad, I'm bad! ... Who's bad :)</div>
</div>

<button onclick="next();">Next</button>

http://codepen.io/anon/pen/kkpJaL

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.