Guidelines for animation
- Use the CSS keyframe animation or CSS transitions, if at all possible. The browser can optimize painting and compositing bigtime here.
- If needs to is it ' s js-based animation, use
requestAnimationFrame
. Avoid setTimeout
, setInterval
.
- Avoid changing inline styles on every frame (jQuery
animate()
-style) If you can, declarative animations in CSS can be optimize D by the browser.
- Using 2D transforms instead of absolute positioning would typically provide better FPS by the by-the-smaller paint times and SM Oother Animation.
- Use Timeline Frame ' s mode to investigate, what's slowing down your behavior
- "Show Paint rects" and "Render composited Layer Borders" is good pro-moves to verify where your element is being rendered .
Animation guidelines
- Use keyframe animation or CSS transition instead of other methods (such as settimeout,requestanimationframe, if conditions permit) Although the latter performance is already very high) the browser can be implemented to optimize the drawing to integrate repetitive work
- If you need to use the JS timer, use Requestanimationfram to avoid using settimeout and setinterval
- Avoid changing inline style directly on elements (as Jquer animate () does) if possible, declaring animations within a CSS file will be more supported by the browser's optimization scheme
- Use 2Dtransform instead of Position:absolute animations, which will result in better FPS frames and smoother animations (make sure Display:block or Display:inline-block)
- Use Timeline Frame ' s mode (inside chrome) to check what causes poor performance
- Using the "Show Paint rects" and "Render composited Layer Borders" features (in Chrome's rendering) is a great way to see your page element rendering process
CSS3 Animations--Basic guidelines