Answer the question
In order to leave comments, you need to log in
Why css animation slows down?
The crux of the matter is as follows. The site has a sidebar (a menu that slides out to the right), the animation of which is built on css-transitions. In the inactive state, the sidebar has the following code:
position: fixed;
top: 0;
bottom: 0;
right: 0;
opacity: 0;
width: 300px;
background: #fff;
z-index: 9999;
-o-transition: all 250ms ease-in-out;
transition: all 250ms ease-in-out;
transform: translate(300px, 0px);
transform: translate(0px, 0px);
opacity: 1;
Answer the question
In order to leave comments, you need to log in
A set of the following actions helped to achieve a smoother animation:
1. The exact property of the transition (ie instead of "transition: all" we specify the specific property with which the animation is performed).
2. The use of class manipulation in JS is not classList, but className. Switching to this solution allowed for real progress in animation fluidity. In particular, this decision was suggested by VK, the same scheme is used there. The className method is included in DOM Core (level 2), has almost complete compatibility with all browsers, and is also more efficiently processed by browser engines with minimal delays.
Perhaps the problem is that the browser has to re-render a lot of elements in the DOM. Try using contain: content.
Native JS, because he's faster.
- will- change
should rather be with opacity
here
both in X and Y. While the value of Y does not change. Yuzaite
transform: translateX(200px);
...
transform: translateX(0px);
Dmitry Maslennikov optimize animation.
specify will-change and instead of all at transition list the properties that you will animate, use translate3d instead of translate
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question