4

I'm trying out a CSS3 animation on a background image. Everything's working well, the problem is that on Chrome the text ends up being blurred when the animation is in progress:

During Animation:

enter image description here

Turning off the animation:

enter image description here

As you can see the text rendering is fine when the animation is turned off, I know there's the usual issue with text rendering but I can't understand why the rendering is poor on Chrome when the animation is in progress. I'm not sure there's anything I can do about it really. I've tested the animation on Firefox and IE and it's ok. By the way I'm working on Windows.

Firefox:

enter image description here

IE:

enter image description here

EDIT

.bg-div {
    position: fixed;
    width: 110%;
    height: 110%;
    transform: translate(-5%, -5%);
    -moz-transform: translate(-5%, -5%) rotate(0.02deg); /* rotation to solve choppy animation on Firefox */
    -ms-transform: translate(-5%, -5%);
    background-image: url('images/colour-test.jpg');
    background-size: cover;
    -webkit-animation: bg-animation 10s linear infinite;
    -moz-animation: bg-animation 10s linear infinite;
    -ms-animation: bg-animation 10s linear infinite;
}

@-webkit-keyframes bg-animation {
    25% { transform: translate(-5.5%, -5.5%); }
    50% { transform: translate(-5.3%, -4.9%); }
    75% { transform: translate(-4.8%, -4.3%); }
}
@-moz-keyframes bg-animation {
    25% { -moz-transform: translate(-5.5%, -5.5%) rotate(0.02deg); }
    50% { -moz-transform: translate(-5.3%, -4.9%) rotate(0.02deg); }
    75% { -moz-transform: translate(-4.8%, -4.3%) rotate(0.02deg); }
}
@-ms-keyframes bg-animation {
    25% { -ms-transform: translate(-5.5%, -5.5%); }
    50% { -ms-transform: translate(-5.3%, -4.9%); }
    75% { -ms-transform: translate(-4.8%, -4.3%); }
}
.content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50%;
    height: 65%;
    text-align: center;
}

After reading the question and answer posted in the comments I've tried to adding -webkit-font-smoothing: subpixel-antialiased; to .bg-div but that didn't make any difference.

EDIT 2

Okay so this is a bit of a weird one, during the animation apparently the position: fixed is making the text blurry. I don't know how that is possible, anyway once I removed the position: fixed and the background was animating the text was displayed correctly. It's still not what I want because I need the background to be fixed.

Daniel Grima
  • 2,765
  • 7
  • 34
  • 58
  • possible duplicate of [Webkit-based blurry/distorted text post-animation via translate3d](http://stackoverflow.com/questions/6411361/webkit-based-blurry-distorted-text-post-animation-via-translate3d) – Zach Saucier Oct 15 '14 at 17:47
  • Thanks for your reply, I did try the solution provided in the posted link however no luck. I'll post the CSS I have just to make things clearer. – Daniel Grima Oct 15 '14 at 20:49
  • Did you try the other suggestion from that thread? `-webkit-transform: translate3d(0,0,0);` – APAD1 Oct 15 '14 at 21:42
  • Yeah I did, no luck as well. It's a weird problem, most of the questions I've found they had problems due to `translate3d` which I'm not using plus as I've mentioned when I remove `position: fixed` everything's back to normal. – Daniel Grima Oct 15 '14 at 21:45
  • `position:fixed` is fairly broken in many different aspects across the board. Avoiding it whenever possible is optimal. You could even try to use absolute positioning with JS, not sure how'd that compare performance wise. Can't be that much worse – Zach Saucier Oct 15 '14 at 22:03
  • Thanks for your reply once more. I did solve the issue using the solution provided below. Mind I ask what's wrong with `position: fixed`? – Daniel Grima Oct 16 '14 at 06:05

1 Answers1

1

In my testing, the problem is fixed if the transform is not used on .content. Luckily, you don't need to use transform to position your content div.

Use this margin: auto trick to position instead

  • Using this method, you do not need to use transform: translate(-50%, -50%)

  • The content is centered with the combination of top, right, bottom, left, margin: auto and the percentage width and height.

.content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 50%;
  height: 65%;
  text-align: center;
}

Working Example

body { margin: 0 auto; width: 500px }

.bg-div {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  width: 800px;
  height: 800px;
  transform: translate(-5%, -5%);
  background: url('http://www.placehold.it/800') no-repeat;
  -webkit-animation: bg-animation 2s linear infinite;
  animation: bg-animation 2s linear infinite;
}
@-webkit-keyframes bg-animation {
  0% {
    transform: translate(-5.5%, -5.5%);
  }
  50% {
    transform: translate(-5%, -5%);
  }
  100% {
    transform: translate(-5.5%, -5.5%);
  }
}
@keyframes bg-animation {
  0% {
    transform: translate(-5.5%, -5.5%);
  }
  50% {
    transform: translate(-5%, -5%);
  }
  100% {
    transform: translate(-5.5%, -5.5%);
  }
}
.content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 50%;
  height: 65%;
  text-align: center;
}
<div class="bg-div"></div>

<div class="content">
  <h1>This looks better</h1>
  <input value="Text" />
</div>
misterManSam
  • 24,303
  • 11
  • 69
  • 89
  • Thanks a lot that did the trick. So I'm guessing that the `transform `is the issue not the `position: fixed`. – Daniel Grima Oct 16 '14 at 05:59
  • 1
    Yes, I think the bug occurs with the combination of both transforms. I have seen this behaviour before, particularly in Chrome, and it is usually due to some combination. It's lucky that you can get the same look with a different method :) It is a bug though, so hopefully less of an issue in the future! – misterManSam Oct 16 '14 at 06:06
  • Yes thankfully it can be solved :) I've noticed that `transform` does seem to cause a few minor but noticeable issues, hopefully they'll be fixed soon. – Daniel Grima Oct 16 '14 at 06:14
  • As an aside, there is no need for `@-ms-keyframes` just use `@keyframes` and `animation`. IE supports the native spec - [browser support is here](http://caniuse.com/#search=keyframes) – misterManSam Oct 16 '14 at 06:19