UNPKG

9.97 kBMarkdownView Raw
1[![AOS - Animate on scroll library](https://s32.postimg.org/ktvt59hol/aos_header.png)](http://michalsnik.github.io/aos/)
2
3[![NPM version](https://img.shields.io/npm/v/aos.svg?style=flat)](https://npmjs.org/package/aos)
4[![NPM downloads](https://img.shields.io/npm/dm/aos.svg?style=flat)](https://npmjs.org/package/aos)
5[![Build Status](https://travis-ci.org/michalsnik/aos.svg?branch=master)](https://travis-ci.org/michalsnik/aos)
6[![Gitter](https://badges.gitter.im/michalsnik/aos.svg)](https://gitter.im/michalsnik/aos?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
7
8[![Twitter Follow](https://img.shields.io/twitter/follow/michalsnik.svg?style=social)](https://twitter.com/michalsnik) [![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/home?status=AOS%20-%20Animate%20on%20Scroll%20library%0Ahttps%3A//github.com/michalsnik/aos)
9
10Small library to animate elements on your page as you scroll.
11
12You may say it's like WOWJS, yeah - you're right, effect is similar to WOWJS, but I had a different idea how to make such a plugin, so here it is. CSS3 driven scroll animation library.
13
14AOS allows you to animate elements as you scroll down, and up.
15If you scroll back to top, elements will animate to it's previous state and are ready to animate again if you scroll down.
16
17πŸ‘‰ To get a better understanding how this actually works, I encourage you to check [my post on CSS-tricks](https://css-tricks.com/aos-css-driven-scroll-animation-library/).
18
19---
20
21### πŸš€ [Demo](http://michalsnik.github.io/aos/)
22
23### 🌟 Codepen Examples
24- [Different build in animations](http://codepen.io/michalsnik/pen/WxNdvq)
25- [With anchor setting in use](http://codepen.io/michalsnik/pen/jrOYVO)
26- [With anchor-placement and different easing](http://codepen.io/michalsnik/pen/EyxoNm)
27- [With simple custom animations](http://codepen.io/michalsnik/pen/WxvNvE)
28
29---
30
31## ❗ Attention
32From version `2.0.0` attributes `aos` are no longer supported, always use `data-aos`.
33
34## βš™ Setup
35
36### Install AOS
37
38- Using `bower`
39
40 ```bash
41 bower install aos --save
42 ```
43
44- Using `npm`
45
46 ```bash
47 npm install aos --save
48 ```
49
50- Direct download -> [click here](https://github.com/michalsnik/aos/archive/master.zip)
51
52
53### Link styles
54
55```html
56 <link rel="stylesheet" href="bower_components/aos/dist/aos.css" />
57```
58
59### Add scripts
60
61```html
62 <script src="bower_components/aos/dist/aos.js"></script>
63```
64
65AOS from version `1.2.0` is available as UMD module, so you can use it as AMD, Global, Node or ES6 module.
66
67### Init AOS
68
69```javascript
70 <script>
71 AOS.init();
72 </script>
73```
74
75## πŸ€” How to use it?
76
77### Basic usage
78
79 All you have to do is to add `data-aos` attribute to html element, like so:
80
81```html
82 <div data-aos="animation_name">
83```
84
85 Script will trigger "animation_name" animation on this element, if you scroll to it.
86
87 [Down below](https://github.com/michalsnik/aos#-animations) is a list of all available animations for now :)
88
89### πŸ”₯ Advanced settings
90
91These settings can be set both on certain elements, or as default while initializing script (in options object without `data-` part).
92
93| Attribute | Description | Example value | Default value |
94|---------------------------|-------------|---------------|---------|
95| *`data-aos-offset`* | Change offset to trigger animations sooner or later (px) | 200 | 120 |
96| *`data-aos-duration`* | *Duration of animation (ms) | 600 | 400 |
97| *`data-aos-easing`* | Choose timing function to ease elements in different ways | ease-in-sine | ease |
98| *`data-aos-delay`* | Delay animation (ms) | 300 | 0 |
99| *`data-aos-anchor`* | Anchor element, whose offset will be counted to trigger animation instead of actual elements offset | #selector | null |
100| *`data-aos-anchor-placement`* | Anchor placement - which one position of element on the screen should trigger animation | top-center | top-bottom |
101| *`data-aos-once`* | Choose wheter animation should fire once, or every time you scroll up/down to element | true | false |
102
103*Duration accept values from 50 to 3000, with step 50ms, it's because duration of animation is handled by css, and to not make css longer than it is already I created implementations only in this range. I think this should be good for almost all cases.
104
105If not, you may write simple CSS on your page that will add another duration option value available, for example:
106
107```css
108 body[data-aos-duration='4000'] [data-aos], [data-aos][data-aos][data-aos-duration='4000']{
109 transition-duration: 4000ms;
110 }
111```
112
113This code will add 4000ms duration available for you to set on AOS elements, or to set as global duration while initializing AOS script.
114
115Notice that double `[data-aos][data-aos]` - it's not a mistake, it is a trick, to make individual settings more important than global, without need to write ugly "!important" there :)
116
117`data-aos-anchor-placement` - You can set different placement option on each element, the principle is pretty simple, each anchor-placement option contains two words i.e. `top-center`. This means that animation will be triggered when `top` of element will reach `center` of the window.
118`bottom-top` means that animation will be triggered when `bottom` of an element reach `top` of the window, and so on.
119Down below you can find list of all anchor-placement options.
120
121#### Examples:
122
123```html
124 <div data-aos="fade-zoom-in" data-aos-offset="200" data-aos-easing="ease-in-sine" data-aos-duration="600">
125```
126```html
127 <div data-aos="flip-left" data-aos-delay="100" data-aos-anchor=".example-selector">
128```
129```html
130 <div data-aos="fade-up" data-aos-anchor-placement="top-center">
131```
132
133
134#### API
135
136AOS object is exposed as a global variable, for now there are three methods available:
137
138 * `init` - initialize AOS
139 * `refresh` - recalculate all offsets and positions of elements (called on window resize)
140 * `refreshHard` - reinit array with AOS elements and trigger `refresh` (called on DOM changes that are related to `aos` elements)
141
142Example execution:
143```javascript
144 AOS.refresh();
145```
146
147By default AOS is watching for DOM changes and if there are any new elements loaded asynchronously or when something is removed from DOM it calls `refreshHard` automatically. In browsers that don't support `MutationObserver` like IE you might need to call `AOS.refreshHard()` by yourself.
148
149`refresh` method is called on window resize and so on, as it doesn't require to build new store with AOS elements and should be as light as possible.
150
151### Global settings
152
153If you don't want to change setting for each element separately, you can change it globally.
154
155To do this, pass options object to `init()` function, like so:
156
157```javascript
158 <script>
159 AOS.init({
160 offset: 200,
161 duration: 600,
162 easing: 'ease-in-sine',
163 delay: 100,
164 });
165 </script>
166```
167
168#### Additional configuration
169
170These settings can be set only in options object while initializing AOS.
171
172| Setting | Description | Example value | Default value |
173|---------------------------|-------------|---------------|---------|
174| *`disable`* | Condition when AOS should be disabled | mobile | false |
175| *`startEvent`* | Name of event, on which AOS should be initialized | exampleEvent | DOMContentLoaded |
176
177##### Disabling AOS
178
179If you want to disable AOS on certain device or under any statement you can set `disable` option. Like so:
180
181```javascript
182 <script>
183 AOS.init({
184 disable: 'mobile'
185 });
186 </script>
187```
188
189There are several options that you can use to fit AOS perfectly into your project, you can pass one of three device types:
190`mobile` (phones and tablets), `phone` or `tablet`. This will disable AOS on those certains devices. But if you want make your own condition, simple type your statement instead of device type name:
191
192```javascript
193 disable: window.innerWidth < 1024
194```
195
196There is also posibility to pass a `function`, which should at the end return `true` or `false`:
197
198```javascript
199 disable: function () {
200 var maxWidth = 1024;
201 return window.innerWidth < maxWidth;
202 }
203```
204
205##### Start event
206
207If you don't want to initialize AOS on `DOMContentLoaded` event, you can pass your own event name and trigger it whenever you want. AOS is listening for this event on `document` element.
208
209```javascript
210 <script>
211 AOS.init({
212 startEvent: 'someCoolEvent'
213 });
214 </script>
215```
216
217**Important note:** If you set `startEvent: 'load'` it will add event listener on `window` instead of `document`.
218
219
220### πŸ‘» Animations
221
222There are serveral predefined animations you can use already:
223
224 * Fade animations:
225 * fade
226 * fade-up
227 * fade-down
228 * fade-left
229 * fade-right
230 * fade-up-right
231 * fade-up-left
232 * fade-down-right
233 * fade-down-left
234
235 * Flip animations:
236 * flip-up
237 * flip-down
238 * flip-left
239 * flip-right
240
241 * Slide animations:
242 * slide-up
243 * slide-down
244 * slide-left
245 * slide-right
246
247 * Zoom animations:
248 * zoom-in
249 * zoom-in-up
250 * zoom-in-down
251 * zoom-in-left
252 * zoom-in-right
253 * zoom-out
254 * zoom-out-up
255 * zoom-out-down
256 * zoom-out-left
257 * zoom-out-right
258
259### Anchor placement:
260
261 * top-bottom
262 * top-center
263 * top-top
264 * center-bottom
265 * center-center
266 * center-top
267 * bottom-bottom
268 * bottom-center
269 * bottom-top
270
271
272### Easing functions:
273
274You can choose one of these timing function to animate elements nicely:
275
276 * linear
277 * ease
278 * ease-in
279 * ease-out
280 * ease-in-out
281 * ease-in-back
282 * ease-out-back
283 * ease-in-out-back
284 * ease-in-sine
285 * ease-out-sine
286 * ease-in-out-sine
287 * ease-in-quad
288 * ease-out-quad
289 * ease-in-out-quad
290 * ease-in-cubic
291 * ease-out-cubic
292 * ease-in-out-cubic
293 * ease-in-quart
294 * ease-out-quart
295 * ease-in-out-quart
296
297## ✌️ [Contributing](CONTRIBUTING.md)
298
299## πŸ“ [Changelog](CHANGELOG.md)
300
301## ❔Questions
302
303If you have any questions, ideas or whatsoever, please check [AOS contribution guide](CONTRIBUTING.md) and don't hesitate to create new issues.