Guidelines for animation
- Use CSS keyframe animation or CSS transitions, if at all possible. The browser can optimize painting and compositing bigtime here.
- If needs to be 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 optimized by the browser way more.
- Using 2D transforms instead of absolute positioning will typically provide better FPS by way of smaller paint times and smoother animation.
- Use Timeline Frame’s mode to investigate what is slowing down your behavior
- “Show Paint Rects” and “Render Composited Layer Borders” are good pro-moves to verify where your element is being rendered.
原文链接:http://www.paulirish.com/2012/why-moving-elements-with-translate-is-better-than-posabs-topleft/