-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvelvet.js
More file actions
46 lines (41 loc) · 1.42 KB
/
velvet.js
File metadata and controls
46 lines (41 loc) · 1.42 KB
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
const velvet = {
init() {
this.observeNewElements();
}
disableAnimations() {
const style = document.createElement('style');
style.id = 'velvet-disable-animations';
style.textContent = `
*:not(.velvet-exclude) {
animation: none !important;
transition: none !important;
transform: none !important;
}
`;
document.head.appendChild(style);
},
enableAnimations() {
const disableStyle = document.getElementById('velvet-disable-animations');
if (disableStyle) {
disableStyle.remove();
}
},
observeNewElements() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach((node) => {
if (node.nodeType === 1 && !node.classList.contains('velvet-animate-in') && !node.classList.contains('velvet-exclude')) {
node.classList.add('velvet-animate-in');
setTimeout(() => {
node.classList.remove('velvet-animate-in');
}, this.settings.duration * 1000);
}
});
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
},
};
window.Velvet = velvet;