-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (63 loc) · 2.25 KB
/
Copy pathapp.js
File metadata and controls
73 lines (63 loc) · 2.25 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
68
69
70
71
72
73
const dateFooter = document.querySelector('#date')
const linkContainer = document.querySelector('.links-container')
const navToggle = document.querySelector('.nav-toggle')
const link = document.querySelector('.links')
navToggle.addEventListener('click', ()=>{
// linkContainer.classList.toggle('show-links')
const containerHeight = linkContainer.getBoundingClientRect().height
const linksHeight = link.getBoundingClientRect().height
if(containerHeight == 0){
linkContainer.style.height = `${linksHeight}px`
}else{
linkContainer.style.height = 0
}
})
dateFooter.innerHTML = new Date().getFullYear();
// Fixed Nav
const navbar = document.getElementById("nav")
const topLink = document.querySelector('.top-link')
window.addEventListener('scroll', function(){
const scrollHeight = window.scrollY
const navHeight = navbar.getBoundingClientRect().height
if(scrollHeight > navHeight){
navbar.classList.add('fixed-nav')
topLink.classList.add('show-link')
}else{
navbar.classList.remove('fixed-nav')
topLink.classList.remove('show-link')
}
})
// Scroll Link Bug
const scrollLink = document.querySelectorAll('.scroll-link')
scrollLink.forEach((link)=>{
link.addEventListener('click', (e)=>{
// preventDefault
e.preventDefault()
// Navigate to specific spot
const id = e.currentTarget.getAttribute('href').slice(1)
const element = document.getElementById(id)
// Calculate the heights
const navHeight = navbar.getBoundingClientRect().height;
const containerHeight = linkContainer.getBoundingClientRect().height
const fixNav = navbar.classList.contains('fixed-nav')
let position = element.offsetTop
console.log(containerHeight)
console.log(fixNav)
if(fixNav){
window.scrollTo({
left:0,
top:position - navHeight - navHeight,
})
}if(navHeight > 82){
window.scrollTo({
left:0,
top:position - navHeight,
})
}if(!fixNav){
window.scrollTo({
left:0,
top:position - containerHeight - navHeight - 82,
})
}
})
})