-
Notifications
You must be signed in to change notification settings - Fork 1
/
humberger.js
47 lines (40 loc) · 1.35 KB
/
humberger.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
// humberger active
const hamburger = document.querySelector('#hamburger')
const navMenu = document.querySelector('#nav-menu')
hamburger.addEventListener('click', function() {
hamburger.classList.toggle('hamburger-active')
navMenu.classList.toggle('hidden')
})
// navbar fixed
window.onscroll = function() {
const header = document.querySelector('header')
const fixedNav = header.offsetTop
if (window.pageYOffset > fixedNav) {
header.classList.add('navbar-vixed')
} else {
header.classList.remove('navbar-vixed')
}
}
// animasi landing page
document.addEventListener('DOMContentLoaded', () => {
const sections = document.querySelectorAll('.animated-section');
const animateSections = () => {
sections.forEach(section => {
if (isElementInViewport(section)) {
section.style.opacity = '1';
section.style.transform = 'translateY(0)';
}
});
};
const isElementInViewport = (el) => {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
animateSections();
window.addEventListener('scroll', animateSections);
});