Prevent flicker on webkit-transition of webkit-tra

2019-01-02 16:15发布

Possible Duplicate:
iphone webkit css animations cause flicker

For some reason, right before my animation of the webkit-transform property occurs, there is a slight flicker. Here is what I am doing:

CSS:

#element {
    -webkit-transition: -webkit-transform 500ms;
}

JavaScript:

$("#element").css("-webkit-transform", "translateX(" + value + "px)");

Right before the transition takes place, there is a flicker. Any idea why this is, and how I could fix the problem?

Thanks!

Update: this only occurs in Safari. It does not happen in Chrome, although the animation does work.

8条回答
步步皆殇っ
2楼-- · 2019-01-02 16:55

Both of the above two answers work for me with a similar problem.

However, the body {-webkit-transform} approach causes all elements on the page to effectively be rendered in 3D. This isn't the worst thing, but it slightly changes the rendering of text and other CSS-styled elements.

It may be an effect you want. It may be useful if you're doing a lot of transform on your page. Otherwise, -webkit-backface-visibility:hidden on the element your transforming is the least invasive option.

查看更多
ら面具成の殇う
3楼-- · 2019-01-02 16:56

I had to use:

-webkit-perspective: 1000;
-webkit-backface-visibility: hidden;    

on the element, or I would still get a flickr the first time a transition occurred after page load

查看更多
伤终究还是伤i
4楼-- · 2019-01-02 16:58

Trigger hardware accelerated rendering for the problematic element. I would advice to not do this on *, body or html tags for performance.

.problem{
  -webkit-transform:translate3d(0,0,0);
}
查看更多
闭嘴吧你
5楼-- · 2019-01-02 17:00

For a more detailed explanation, check out this post:

http://www.viget.com/inspire/webkit-transform-kill-the-flash/

I would definitely avoid applying it to the entire body. The key is to make sure whatever specific element you plan on transforming in the future starts out rendered in 3d so the browsers doesn't have to switch in and out of rendering modes. Adding

-webkit-transform: translateZ(0) 

(or either of the options already mentioned) to the animated element will accomplish this.

查看更多
不流泪的眼
6楼-- · 2019-01-02 17:01

The solution is mentioned here: iPhone WebKit CSS animations cause flicker.

For your element, you need to set

-webkit-backface-visibility: hidden;
查看更多
栀子花@的思念
7楼-- · 2019-01-02 17:03

Add this css property to the element being flickered:

-webkit-transform-style: preserve-3d;

(And a big thanks to Nathan Hoad: http://nathanhoad.net/how-to-stop-css-animation-flicker-in-webkit)

查看更多
登录 后发表回答