Considerations for CSS3 Transition Performance

前端 未结 4 739
一个人的身影
一个人的身影 2021-02-02 01:43

As part of a project that needs to support mobile devices, I have been working on mimicking the iPhone toggle control using CSS3. I have the look and feel of the element pretty

4条回答
  •  無奈伤痛
    2021-02-02 02:35

    You have to be careful with this, as it can alter the z-index of the element it's applied to, but adding:

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

    To the element you're applying the transition to, can speed animation up considerably, as it forces the hardware to use hardware acceleration for the animation.

    If you do encounter layout bugs, you can just switch your 2d transitions to 3d values, so:

    -webkit-transform: translate(100px, 100px)
    

    becomes:

    -webkit-transform: translate3d(100px, 100px, 0px)
    

    You can see a demo of how this helps speed things up, at http://stickmanventures.com/labs/demo/spinning-gears-Chrome-preserve-3d/#

    If after applying this to the element, you see it or elements around it blink upon use, then use:

    -webkit-backface-visibility: hidden;
    

    To the element, and that should correct the problem.

    These tips have helped me to produce fast, efficient CSS transitions, hope they help. :)

提交回复
热议问题