-
Notifications
You must be signed in to change notification settings - Fork 1
/
aos.js
59 lines (50 loc) · 1.77 KB
/
aos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
after putting this code inside script tag or external linked js file
use ( as ) before animate__animated and use ( s_ ) before animte_ prefix
example -
<h2 class="as animate__animated s_animate__rotateInDownLeft">harindu</h2>
with this code 👆👆👆
<h2 class="animate__animated animate__rotateInDownLeft">harindu</h2>
normal animate.css 👆👆👆
*/
aaosInit({
root: '#scrollArea',
rootMargin: '0px',
threshold: 0.1,
aaosClassName: 'as'
})
function aaosInit(anchor) {
let aaosClassName = 'as'
let options
if (anchor && (typeof anchor) == 'object')
options = anchor
else
options = {
root: document.querySelector(anchor || document.body),
rootMargin: '0px',
threshold: 0.9
}
if (options && options.aaosClassName) aaosClassName = options.aaosClassName
if (options && options.root && (typeof options.root) == 'string') options.root = document.querySelector(options.root)
let observer = new IntersectionObserver(callback, options);
let targets = document.getElementsByClassName(aaosClassName)
for (var i = 0; i < targets.length; i++)
observer.observe(targets[i]);
function callback(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting)
replaceClass(entry.target)
});
};
function replaceClass(target) {
var classList = target.classList
for (var i = 0; i < classList.length; i++) {
if (classList[i].startsWith('s_animate')) {
var klass = classList[i]
target.classList.remove(classList[i])
target.classList.add(klass.substring(2))
target.classList.remove(aaosClassName)
}
}
}
}