CSS Transform causes flicker in Safari, but only when the browser is >= 2000px wide

58,554

Solution 1

Frustrating huh?

See EDIT4 for the answer to why 2000px is a magic number.

There is a couple of things you can try.

  • Add -webkit-transform-style: preserve-3d; to the elements that are flickering.

  • add -webkit-backface-visibility: hidden; to the elements that are
    flickering.

  • move the animating element outside of the parent the flickering
    elements are within.

EDIT — Wesley Hales, said here "I encountered glitchy behaviour when applying hardware acceleration to parts of the page that were already accelerated"

Its hard to help you debug this without any code. But for starters I suggest you turn on debug mode in safari. Write 'defaults write com.apple.Safari IncludeInternalDebugMenu -bool true' in the terminal.

After this a Debug menu will show up. Choose Drawing/Compositing flags > Show Compositing borders.

This will help you see whats being rendered and by that choose what to put in hardware acceleration and what to leave out.

EDIT2 — This is worth checking out as well: fast-animation-with-ios-webkit

Its regarding iOs, but I've experienced that - in some circumstances - solutions that work on iOs also works on osx.

EDIT3 — If you are just asking what happens when its bigger than 2000px I can tell you for sure that on iPhones, WebKit creates textures that are no larger than 1024 by 1024, and if your element is larger than that, it has to create multiple textures.

Documentation on texture limitations

Now, when they do it on iPhone, it wouldn't surprise me if they do the same on OsX, but has a higher limit.

Don't know if this is your case tho. Impossible to tell without any code.

EDIT4 — "The implementation in TextureMapperTiledBackingStore is pretty simple, and is used only to work around the 2000x2000 texture size limitation in OpenGL."

So, if your element is bigger than 2000x2000 it has to create multiple textures.

http://trac.webkit.org/wiki/CoordinatedGraphicsSystem

Solution 2

I found that applying the -webkit-backface-visibility: hidden; to the translating element and -webkit-transform: translate3d(0, 0, 0); to all its children, the flicker then disappears.

Please refer Prevent flicker on webkit-transition of webkit-transform.

Solution 3

If the fonts are flickering use the following CSS:

html,body {
    -webkit-font-smoothing: antialiased;    
}

Solution 4

I noticed that after applying CSS3 transforms elements in Chrome looks a bit "crispy" and text unaligned. Solutions in Mathias answer have no effect on this. But here is strange thing - after I've applied webkit filters (i.e. -webkit-filter: opacity(0.99999);), elements rendered properly and letters in text are aligned. But after that those elements looks blured a bit. Maybe this have effect on your flickering.

Share:
58,554
Brandon Durham
Author by

Brandon Durham

Over 16 years of experience in interactive development and design, looking for a progressive and collaborative company where individual voices are valued.

Updated on July 09, 2022

Comments

  • Brandon Durham
    Brandon Durham almost 2 years

    You read that right. Tested on multiple machines in the office and the only difference between scenarios was browser size. A coworker narrowed it down to a 2000px sweet spot. Lo-and-behold when we each resize our browsers to be >= 2000px wide and mouse over an element with a transform animation various elements on the page — specifically any element with a CSS gradient background — will flicker. Inversely, if you resize the browser to be < 2000px wide and mouse over that same element no flickering occurs.

    Anyone else seen this bizarre behavior? Why is 2000px a magic number, and what exactly happens at 2000px?

    NOTE — I can't really share screenshots/video/links as this site isn't yet public, and code is relatively unnecessary as this seems to be more of a browser issue than anything.

    NOTE 2 — My question here is really around what exactly happens in Safari at 2000px, not necessarily how to fix the flicker with backface-visibility or translateZ or the like. Reason being that we use -webkit-font-smoothing: subpixel-antialiased; liberally throughout the site and using any of these tricks trumps that property for the entire page, turning on antialiasing / grayscale for all text.

    EDIT — Okay, sorry for not having done this earlier. Here is a bit of code in a jsFiddle that should reproduce the issue: http://jsfiddle.net/brandondurham/ujPMK/embedded/result/

    Remember, Safari has to be set to at least 2000px wide for this to happen.

  • yunzen
    yunzen about 11 years
    I think the opacity trigger -webkit-font-smooting stackoverflow.com/questions/6846953/…
  • Miljan Puzović
    Miljan Puzović about 11 years
    @HerrSerker, opacity is just example. Same happens with ALL webkit filters. Also, direct using of -webkit-font-smooting don't work in my case. I can't notice any difference.
  • ARF
    ARF about 11 years
    Is this related on how I can't create a very big canvas elements (9000x9000 pixels) on the iPad3? I haven't tested on other iPad versions
  • Spoeken
    Spoeken about 11 years
    I believe so. But you can create multiple canvases instead.
  • ARF
    ARF about 11 years
    I actually tried that, if the sum of all the canvas areas are bigger than 9000x9000 pixels it still doesn't render. When I first found out about this I thought that I was reaching the limit of iPad3 video memory. Worth of note that this also happened on Chrome on my notebook, but the limit was higher (16kx16k I believe).
  • Spoeken
    Spoeken about 11 years
    You should post a new question for this with some code. For all I know you can have a media query with display: none; on canvas - not saying thats the case tho :)
  • wavetree
    wavetree almost 11 years
    I'm not sure why you had downvotes, but applying this (with the added "-webkit" prefix) on the children fixed the flicker on Safari 5.1 for me. So here's an upvote. :)
  • Malte Schulze-Boeing
    Malte Schulze-Boeing almost 11 years
    This did the trick for me :-) body { -webkit-backface-visibility: hidden; }
  • Rupam Datta
    Rupam Datta about 10 years
    @gnclmorais Thanks for the edit but should I ask you what is the change you made?
  • gnclmorais
    gnclmorais about 10 years
    Nothing crucial, just put the CSS rules in code blocks. I'm a little OCD about it. By the way, your answer helped me, it removed the flicker from my headers! I just needed the -webkit-backface-visibility. So thank you. :)
  • Hooman Askari
    Hooman Askari over 9 years
    In my case adding -webkit-transform:translateZ(0) to the flickering items did the job. To my surprize I only had to assign the fix to p and a elements on my site.
  • Bojana Šekeljić
    Bojana Šekeljić almost 9 years
    This is a good answer as on safari, translate3d() uses hardware acceleration, as opposed to translateY(), translateX().
  • dakab
    dakab over 8 years
    The OP said they were already using this property. Anyway, you could improve your answer by adding documentation resources and explanation how this would help.
  • rkd
    rkd about 6 years
    Wildcard CSS selectors aren't great for performance, the more elements you add to page the more matches and css updates occur
  • rkd
    rkd about 6 years
    That feature flag for Safari to show compositing layers is huge. Very helpful.
  • Chet
    Chet about 6 years
    I get that... but it works. Not sure why people are down-voting. Its running in a very performant web application...
  • rkd
    rkd about 6 years
    It definitely works, but it's like burning a forest to remove a single tree. I don't doubt it works fine in some cases/may not always cause problems, but don't think its a very tactical approach
  • Chet
    Chet about 6 years
    Yeah, I actually removed this code and drastically improved the performance on Android haha. Not seeing the flicker anymore either so its a win win!
  • Raphael Aleixo
    Raphael Aleixo about 4 years
    Wow. Thanks, I would never guess that an element size would cause problems. Changing to multiple elements fixed everything. :)
  • cuka
    cuka almost 4 years
    +1 because using the wildcard helped me find the element that needed the rule. Then removed the wildcard and specifically targeted the element.