-
Notifications
You must be signed in to change notification settings - Fork 1
/
orellax.js
39 lines (30 loc) · 1013 Bytes
/
orellax.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
const orellax = (function () {
const items = document.querySelectorAll('.orellax');
const options = {
root: null,
rootMargin: "0% 0% -160px",
threshold: [0, 0.5, 1.0]
};
function isIntersect(entries) {
for (let i = 0; i < entries.length; i++) {
const e = entries[i];
const isAbove = e.boundingClientRect.y < e.rootBounds.y;
if (e.isIntersecting) {
e.target.classList.add('is-orellaxActive');
e.target.classList.remove('is-orellaxOver', 'is-orellaxReady');
} else {
e.target.classList.remove('is-orellaxActive');
if (e.boundingClientRect.y < e.rootBounds.y) {
e.target.classList.add('is-orellaxOver');
}
}
}
}
const observer = new IntersectionObserver(isIntersect, options);
// Polyfill を使わない場合は下記を削除
observer.POLL_INTERVAL = 100;
for (let i = 0; i < items.length; i++) {
items[i].classList.add('is-orellaxReady');
observer.observe(items[i]);
}
})();