-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchContent.js
34 lines (30 loc) · 1.04 KB
/
switchContent.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
const switchContent = (target) => {
document.querySelector('.Jump.Nav-button.Active').classList.remove('Active')
target.classList.add('Active')
}
const scrollObserverCallback = (entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
let target = entry.target
if (target.className === 'Card Project') target = target.parentElement
switchContent(document.querySelector(`#${target.id.match(/^.*?(?=-)/)}`))
}
})
}
const observer = new IntersectionObserver(scrollObserverCallback, {
root: document.querySelector('#app'),
rootMargin: '0px',
threshold: 1.0,
})
document.querySelectorAll('.Jump').forEach((button) => {
let proj = button.id === 'Proj'
if (button.id !== 'Proj') observer.observe(document.querySelector(`#${button.id}-Content`))
button.addEventListener('click', () => {
proj ?
document.querySelector(`#ProjStart`).scrollIntoView(false) :
document.querySelector(`#${button.id}-Content`).scrollIntoView(false)
})
})
document.querySelectorAll('.Project').forEach((project) => {
observer.observe(project)
})