{"id":242456,"date":"2016-06-06T06:06:14","date_gmt":"2016-06-06T13:06:14","guid":{"rendered":"http:\/\/css-tricks.com\/?p=242456"},"modified":"2017-04-10T17:48:11","modified_gmt":"2017-04-11T00:48:11","slug":"aos-css-driven-scroll-animation-library","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/aos-css-driven-scroll-animation-library\/","title":{"rendered":"AOS: CSS-Driven “On Scroll” Animation Library"},"content":{"rendered":"

The following is a guest post by Micha\u0142 Sajn\u00f3g<\/a>, a front end developer at Netguru<\/a>. Micha\u0142 has created one of those “when you scroll to here, trigger this animation” libraries. One of the things I like about it is that it leaves as much as it can to CSS for creating and controlling the animation themselves. Not to mention it’s proved itself by working well on a number of production sites. I’ll let Micha\u0142 walk you through it.<\/em><\/p>\n

<\/p>\n

Have you ever seen those long web pages where different animations are being applied as you scroll down? I\u2019d like to share with you a plugin I wrote that makes it really easy to handle all kinds of animations with full CSS control and no pain.<\/p>\n

If you’d like to get right into it, the code is on GitHub.<\/a><\/p>\n

The Problem With Other Libraries<\/h3>\n

In my previous company we were using WOW.js<\/a> (or other similar libraries) to animate elements on scroll. For simple projects it was quite nice, but on larger sites we wanted to have more control over what\u2019s actually happening. In all of popular libraries, animations were completely handled by JavaScript by inserting inline CSS. Arghgh! Inline styles are evil. They are hard to control and override. Though, in some cases it\u2019s ok to set them using JavaScript, it\u2019s still much cleaner to just leave them where they belong and handle all CSS related things inside CSS file.<\/p>\n

I decided to create a library that has a pure goal – detect position of elements and then add appropriate classes when they appear in viewport.<\/p>\n

Controlling Animations Entirely in CSS<\/h3>\n

I wanted to split the responsibilities with my new library:<\/p>\n