-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (58 loc) · 2.06 KB
/
Copy pathscript.js
File metadata and controls
67 lines (58 loc) · 2.06 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
const themeToggleBtn = document.querySelector('#theme-toggle');
const body = document.body;
const icon = document.querySelector(".icon");
const hamburgerBtn = document.querySelector("#hamburger");
const navLinksContainer = document.querySelector(".nav-links");
const navLinks = document.querySelectorAll(".nav-links li a");
hamburgerBtn.addEventListener("click",()=>{
navLinksContainer.classList.toggle("active");
if(navLinksContainer.classList.contains("active")){
hamburgerBtn.textContent = "✕";
}else{
hamburgerBtn.textContent = "☰";
}
})
navLinks.forEach(link => {
link.addEventListener("click",()=>{
navLinksContainer.classList.remove("active");
hamburgerBtn.textContent = "☰";
});
});
themeToggleBtn.addEventListener('click',()=>{
body.classList.toggle('light-mode');
if(body.classList.contains('light-mode')){
localStorage.setItem('theme','light');
icon.textContent = "🌙";
}else{
localStorage.setItem('theme','dark');
icon.textContent = "☀️";
}
});
const currentTheme = localStorage.getItem('theme');
if(currentTheme === "light"){
body.classList.add('light-mode');
icon.textContent = '🌙';
}
// INTERSECTION OBSERVER
// 1.Set rules for observer
const observerOptions = {
root:null,// Uses the viewport as the bounding box
rootMargin:'0px',
threshold:0.15// Triggers when 15% of the card is visible on screen
};
// 2. Create the observer
const observer = new IntersectionObserver((entries,observer)=>{
entries.forEach(entry=>{
// If the card crosses the threshold into view...
if(entry.isIntersecting){
// Add the visible class to trigger the CSS animation
entry.target.classList.add('visible');
// Stop watching this specific card so it doesn't animate out and in repeatedly
observer.unobserve(entry.target);
}
});
},observerOptions);
// 3. Command the observer to watch every project card
document.querySelectorAll('.scroll-element').forEach(el=>{
observer.observe(el);
})