-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportfolio.js
More file actions
68 lines (52 loc) · 1.69 KB
/
Copy pathportfolio.js
File metadata and controls
68 lines (52 loc) · 1.69 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
const head = document.querySelector('.head');
//when scrolling the page
window.addEventListener('scroll',function(){
const h = head.getBoundingClientRect().height
const page = window.pageYOffset
if(page > h){
head.classList.add("rect")
}else{
head.classList.remove("rect")
}
}
)
//Editing a responsive bar after minimizing the acreen to a max-height
const tog = document.querySelector('.tog')
const navlinks = document.querySelector('.nav-links')
const na = document.querySelector('.na')
tog.addEventListener('click', function(){
const naheight = na.getBoundingClientRect().height
const linksheight = navlinks.getBoundingClientRect().height
if(naheight == 0){
na.style.height = `${linksheight}px`
}else{
na.style.height =0
}
})
const scrollLinks = document.querySelectorAll('.scroll-link');
scrollLinks.forEach((e)=>{
e.addEventListener('click', function(o){
o.preventDefault()
//calculate scroll
const headheight = head.getBoundingClientRect().height
const fixHead = head.classList.contains("rect")
const naheight = na.getBoundingClientRect().height
//navigate to specific spot
const id = o.currentTarget.getAttribute('href').slice(1)
const element = document.getElementById(id)
let position = element.offsetTop-headheight
if(!fixHead){
position = position-headheight
}
if(headheight> 70){
position= position+naheight
}
console.log(headheight);
//scroll method
window.scrollTo({
left:0,
top:position
})
na.style.height =0
})
})