-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (57 loc) · 2.05 KB
/
script.js
File metadata and controls
79 lines (57 loc) · 2.05 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(function(){
if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.querySelectorAll('.reveal').forEach(el => el.classList.add('active'));
return;
}
const reveals = document.querySelectorAll('.reveal');
const observerOptions = {
root: null,
rootMargin: '0px 0px -10% 0px',
threshold: 0.15
};
const observer = new IntersectionObserver((entries, obs) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const el = entry.target;
const delayAttr = el.getAttribute('data-delay');
if (delayAttr) {
el.style.transitionDelay = `${delayAttr}ms`;
} else {
}
el.classList.add('active');
obs.unobserve(el);
}
});
}, observerOptions);
reveals.forEach(el => observer.observe(el));
if (!('IntersectionObserver' in window)) {
window.addEventListener('scroll', fallbackThrottle);
window.addEventListener('resize', fallbackThrottle);
fallbackThrottle();
function fallbackThrottle() {
if (window._revealTimeout) clearTimeout(window._revealTimeout);
window._revealTimeout = setTimeout(checkFallback, 100);
}
function checkFallback() {
const viewportTop = window.scrollY;
const viewportBottom = viewportTop + window.innerHeight;
document.querySelectorAll('.reveal').forEach(el => {
const rect = el.getBoundingClientRect();
const elTop = rect.top + window.scrollY;
const elBottom = elTop + rect.height;
// se 15% do elemento estiver visível
const visible = (elBottom - (rect.height * 0.85)) <= viewportBottom && (elTop + (rect.height * 0.15)) >= viewportTop;
if (visible) {
el.classList.add('active');
}
});
}
}
})();
document.querySelectorAll('a[href^="#"]').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href'))
.scrollIntoView({ behavior: 'smooth' });
});
});