What I Read

Web Animation Techniques - CSS vs JavaScript

ウリ김영은 2023. 11. 11. 12:04

원문

CSS Animations (Cascading Style Sheets)

CSS is commonly used for styling web pages and animation

Advantages of CSS Animations

  • Easy to Use: relatively simple to implement
  • Performance : they are hard-ware accelerated and generally perfom well, providing a smooth user experience.
  • Responsive Design : they are inherently responsive ; adapt to different screen sizes and devices
  • Low JS Overhead : reduce the load on JS, making web application more efficient
  • Broswer Compatibility

JavaScript Animations

JS animations are typically more flexible and capable of handling intricate, data-driven animations

using requestAnimationFrame method

Other common JS animation methods

  • jQuery
  • GreenSock Animation (GSAP)
  • Web Animation API
  • SVG Animations

Advantages of JavaScript Animations

  • Complex Animations : offers greater flexibility, making it suitable for complex animations with dynamic behavior
  • Data-Driven Animations : allows to create animations based on data, making dynamic content
  • Real-Time Updates : can be used for real-time updates and synchronized animations with the web applicaition
  • Performance Implications : sometimes can be resource-intensive

When to use CSS vs JavaScript

When to use CSS

  • basic animations like hover effects, transitions, and small, non-interactive animations

  • is more smoother & efficient => good for performance

  • adapt to different screen sizes seamlessly

When to use JavaScript

  • when creating intricate animations with dynamic elements

  • when it need to repsong to user interactions

  • essential for creating interactive charts and graphs for data-driven animations

  • when real-time updates or synchronnized animations are needed

How to Combine CSS & JavaScript

  • CSS for initial(when page loads) animations and transitions

  • JavaScript for user interactions, real-time updates, data-driven animations

=> provide the efficiency & performance benefits