1

I am using css animation but it seems to be a bit sluggish on some pages, I believe due to the CPU usage.

.test {
left:50%;
position:relative;
overflow:hidden;
animation: waitandhide2 2.2s 0s, show2 2.2s 2.2s;
-webkit-animation: waitandhide2 2.2s 0s, show2 2.2s 2.2s;
-moz-animation: waitandhide2 2.2s 0s, show2 2.2s 2.2s;
animation-timing-function: ease-in-out;
-moz-animation-timing-function: ease-in-out;
-webkit-animation-timing-function: ease-in-out;
z-index:5;
}

@keyframes waitandhide2 {
    from { left:50%; opacity:1; }
    to { left:-105%; opacity:1; }
}
@keyframes show2 {
    from { left:105%; opacity:1; }
    to { left:50%; opacity:1; }
}
@-webkit-keyframes waitandhide2 {
    from { left:50%; opacity:1; }
    to { left:-105%; opacity:1; }
}
@-webkit-keyframes show2 {
    from { left:105%; opacity:1; }
    to { left:50%; opacity:1; }
}
@-moz-keyframes waitandhide2 {
    from { left:50%; opacity:1; }
    to { left:-105%; opacity:1; }
}
@-moz-keyframes show2 {
    from { left:105%; opacity:1; }
    to { left:50%; opacity:1; }
}

I have read somewhere that you can fix this by using -webkit-transform: translate3d(0, 0%, 0); I have no idea how to do this in this scenario.

Any help is appreciated.

2
  • 1
    CSS3 animations are hardware accelerated, the're supposed to use the GPU, not the CPU that much. Maybe if you can provide a fiddle, other users can test and tell you if the animation if fluid on their machines or not. Commented Feb 17, 2015 at 21:13
  • It seems to be more of an issue when it is trying to run on page load. Repeating the animation runs smoothly, when there is nothing else loading, I have delayed the css animation on initial load and it seems to be okay now. Commented Feb 17, 2015 at 21:36

2 Answers 2

1

Instead of animating left:% propriety, animate translate: transform(%). Adding -webkit-transform: translate3d(0, 0%, 0) and the animated element will create a separate layer and may help with performance. This is however a hack, you should use will-change propriety for this.

Sign up to request clarification or add additional context in comments.

Comments

1

I have corrected this issue by delaying the animation onload.

It seems to be more of an issue when it is trying to run on page load, while the page is downloading many other elements, and images.

It more noticeable on larger pages, which made sense. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.