-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
35 lines (35 loc) · 1.19 KB
/
main.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
//Header
let ariaExpanded = false;
const hamburgerBtn = document.getElementById("burger-menu");
hamburgerBtn.onclick = () => {
ariaExpanded = !ariaExpanded
hamburgerBtn.ariaExpanded = String(ariaExpanded);
if (ariaExpanded) {
document.body.classList.add("menu-is-open");
}
else {
document.body.classList.remove("menu-is-open");
}
}
//header//
//hero-section//
const pointerFollower = document.getElementById("pointerFollower");
const heroSection = document.querySelector(".hero-sec")
let coordinates = { x: 0, y: 0 }
function trackMouse(e) {
const usingClientRect = heroSection.getBoundingClientRect();
coordinates.x = e.clientX - usingClientRect.left;
coordinates.y = e.clientY - usingClientRect.top;
pointerFollower.style.transform = `translate(${coordinates.x}px, ${coordinates.y}px)`
}
const heroSectionObs = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
document.body.addEventListener("mousemove", trackMouse);
pointerFollower.style.scale = 1
}
else {
document.body.removeEventListener("mousemove", trackMouse)
pointerFollower.style.scale = null
}
})
heroSectionObs.observe(heroSection)