8

http://jsfiddle.net/danielcgold/SYgzJ/

When you click on the input then go on blur, artifacts are left on the screen in Chrome 15. I first noticed this issue on a site i've been developing so I eliminated everything but just the input field and a button. When I remove the button, the transition happens just fine. Any ideas?

c69
  • 19,951
  • 7
  • 52
  • 82
Dan
  • 3,338
  • 5
  • 36
  • 58

3 Answers3

11

Add this CSS to your input field:

input {
    -webkit-transform: translate3d(0,0,0)
}

This will force Chrome to use your GPU to do all the rendering which will solve the artifacts problem and make your animations smother.

Cesar Canassa
  • 18,659
  • 11
  • 66
  • 69
  • This worked. When I applied this property to my style block where I set all my transitions, it broke something in my layout. I just set this property through a class and it worked! – Dan Nov 11 '11 at 16:13
  • 1
    This can cause another problem: z-index could be messed up. [See here to handle it](http://stackoverflow.com/questions/6953497/webkit-transform-overwrites-z-index-ordering-in-chrome-13). – yves amsellem Jan 16 '14 at 13:57
3

This is a bug in Chrome's rendering of CSS transitions. But you can workaround it by forcing element "refresh" operation. Please note that you need to refresh not the input element, but it's parent, so the following code will help you:

$(document).ready(function(){
    $('#test').blur(function(){
      $(this).parent().addClass('repaint');
    });
    $('#test').focus(function(){
      $(this).parent().removeClass('repaint');
    });
});

And repaint class should have something related to parent's view, for example different color:

.repaint {
 color: red;
}

But you may replace color with visibility or other view-related (but not important/visible for parent) attribute.

Here is jsfiddle to demonstrate the workaround

Pavel Podlipensky
  • 8,201
  • 5
  • 42
  • 53
  • This did not work, I tried applying class to animated element as well as body using the `jQuery` callback as well as `promise().done()` The `translate3d` solution did work... – Serj Sagan Jun 19 '14 at 02:10
0

I had a similar problem with box shadow artifacts in Safari, and found adding -webkit-transform:scale(1); to the focus rule fixed the problem.

See http://jsfiddle.net/SYgzJ/48/ – it should work fine now.

As Cesar said, -webkit-transform: translate3d(0,0,0); will fix it, but it can affect text rendering too.

Musket
  • 8,585
  • 2
  • 16
  • 9