Safari changing font weights when unrelated animations are running

我与影子孤独终老i 提交于 2019-12-17 15:17:15

问题


I'm using css animations on my page and Safari seems to change unrelated font weights elsewhere on the page when animations are running. Any idea why this happens? All other browsers work fine, include webkit ones like Chrome.

I've detailed the bug in a video here - http://www.screenr.com/gZN8

The site is also here - http://airport-r7.appspot.com/ but it might keep changing rapidly.

I'm using compass (@transition-property, @transition-duration) on the arrow icons. No transitions applied on the heading that's flashing. On a Mac - so it might be the hardware acceleration, but I'm still trying to figure it out.


回答1:


When you trigger GPU compositing (eg, through CSS animation), the browser sends that element to the GPU, but also anything that would appear on top of that element if its top/left properties were changed. This includes any position:relative elements that appear after the animating one.

The solution is to give the animating element position:relative and a z-index that puts it above everything else. That way you get your animation but keep the (superior IMO) sub-pixel font rendering on unrelated elements.

Here's a demo of the problem and solution http://www.youtube.com/watch?v=9Woaz-cKPCE&hd=1

Update: Newer versions of Chrome retain sub-pixel antialiasing on GPU composited elements as long as the element has no transparency, eg has a background with no transparent or semi-transparent pixels. Note that things like border-radius introduce semi-transparent pixels.




回答2:


Apparently, that's the price you pay for hardware acceleration: all text momentarily turns into images, which causes the drop in render quality.

However, applying html {-webkit-font-smoothing: antialiased} to turn off the sub-pixel anti-aliasing makes this problem go away. That's what I'm doing for now.

UPDATE: Since then, I've also come to learn that this happens only when the browser can't be sure if the section being animated is going to affect the text. This can usually be handled by having the text above (higher z-index than) the elements being animated, and/or making sure the text has a fully opaque background.




回答3:


I've faced this issue numerous times and have had success adding the following css to the animated element:

z-index: 60000;
position: relative;

It seems it needs both z-index and position to be effective. In my case I was using it with Font Awesome animated spinners.



来源:https://stackoverflow.com/questions/9733011/safari-changing-font-weights-when-unrelated-animations-are-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!