-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (31 loc) · 1.07 KB
/
index.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
// Hamburger Menu
const hamMenuBtn = document.getElementById('ham-menu-btn');
const hamMenuItems = document.getElementById('ham-menu-items');
hamMenuBtn.addEventListener('click', () => {
hamMenuBtn.classList.toggle('open');
hamMenuItems.classList.toggle('unfold');
hamMenuItems.classList.toggle('close');
});
// animated arrow, onclick to main
function toMain() {
let scrollToTransformText = document.getElementById('firstText');
scrollToTransformText.scrollIntoView();
}
// Intersection Observer API for back-to-top button, visibility on scroll and animation via clasList.add
const target = document.querySelector('.topBtn');
function handleIntersection(entries) {
entries.map((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('topBtn-anim');
} else {
entry.target.classList.remove('topBtn-anim');
}
});
}
const observer = new IntersectionObserver(handleIntersection);
observer.observe(target);
// back to top button, onclick to hero
function backToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}