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

ICE
  • 1,667
  • 2
  • 21
  • 43
  • 1
    Can't reproduce on Chrome v53: https://jsfiddle.net/1x8azozx/ – nkmol Oct 13 '16 at 07:34
  • 1
    @nkmol you can try it with codepen: http://codepen.io/anon/pen/kkpJaL – ICE Oct 13 '16 at 07:53
  • 1
    I am on chrome using OSX no blurryness here FYI – Mathijs Segers Oct 13 '16 at 08: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: http://codepen.io/anon/pen/kkpJaL – ICE Oct 13 '16 at 08:53
  • OSX has no problems with your code pen, both texts look the same and they're clear no blurryness at all. Note I am on a retina (double pixel) screenz. – Mathijs Segers Oct 13 '16 at 09:27
  • 1
    @MathijsSegers Thanks. It must be something to get it fixed on Linux and Windows. – ICE Oct 13 '16 at 11:14
  • 1
    @ICE fyi cant reproduce on win chrome 54 anyway good luck :) – Jaqen H'ghar Oct 15 '16 at 21:13
  • 1
    I deal with this issue all the time, @Code Spirit's answer is correct. It's not just text either, this can happen with images as well. – asimovwasright Oct 16 '16 at 08:31
  • 1
    @asimovwasright That answer can't solve the problem. I already mentioned that on my question. – ICE Oct 16 '16 at 08:38
  • For me adding -webkit-backface-visibility: hidden; -webkit-transform: translateZ(0) scale(1.0, 1.0); to the body did help the end result – GeNyaa Oct 21 '16 at 13:05

5 Answers5

10

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

serraosays
  • 7,163
  • 3
  • 35
  • 60
  • 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 03 '19 at 21:27
  • @ICE - can you post an example answer? I'm curious where you're still seeing issues. This site I built (http://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 03 '19 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 03 '19 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.

Code Spirit
  • 3,992
  • 4
  • 23
  • 34
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+)

L1ghtk3ira
  • 3,021
  • 6
  • 31
  • 70
  • 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 '19 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 '19 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;
}
Angelica
  • 197
  • 14
-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

amit bende
  • 264
  • 3
  • 4