CSS keyframe animation CPU usage is high, should it be this way?

前端 未结 5 1015
梦毁少年i
梦毁少年i 2020-12-12 12:34

I use following keyframe animation on several elements:

@keyframes redPulse {
    from { background-color: #bc330d; box-shadow: 0 0 9px #333; }
    50% { bac         


        
5条回答
  •  时光说笑
    2020-12-12 13:07

    I had a similar case of high CPU usage when animating some elements with CSS3. I was animating the "left"-property of ~7 elements, with some opacity- and shadow-properties used in my whole page. I decided to switch to jQuery.animate, which sadly didn't improve the performance at all. My CPU (i7) was still at ~9-15% while displaying the page, several tricks (translateZ, etc) didn't really improve the performance either - while having my layout messed up (some absolute-positioned elements were involved, ouch!).

    Then I stumbled upon this wonderful extension: http://playground.benbarnett.net/jquery-animate-enhanced/

    I simply referenced the .js-file, didn't make a single change at the jQuery transitions, and my CPU usage is now 1-2% on the very same page.

    My recommendation: when facing CPU issues using CSS3 transitions, switch to jQuery + the animate-enhanced-plugin.

提交回复
热议问题