-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (54 loc) · 1.94 KB
/
script.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
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
const primaryNav = document.querySelector(".primary-nav");
const navToggle = document.querySelector(".mobile-nav-toggle");
const navLink = document.querySelectorAll(".nav-link");
navToggle.addEventListener("click", () => {
const visibility = primaryNav.getAttribute("data-visible");
if (visibility === "false") {
primaryNav.setAttribute("data-visible", true);
navToggle.setAttribute("aria-expanded", true);
}
if (visibility === "true") {
primaryNav.setAttribute("data-visible", false);
navToggle.setAttribute("aria-expanded", false);
}
});
[...navLink].forEach((nav) => {
nav.addEventListener("click", () => {
if (primaryNav.getAttribute("data-visible") === "true") {
primaryNav.setAttribute("data-visible", false);
navToggle.setAttribute("aria-expanded", false);
}
});
});
var typed = new Typed(".typing", {
strings: ["front-end developer","web designer","graphic designer", "computer technician"],
typeSpeed: 100,
backSpeed: 60,
loop: true
});
let navbar1 = document.getElementById("primary-nav");
let viewportHeight = window.innerHeight;
let navHeight = document.getElementById("primary-nav").offsetHeight;
let navbarLinks = document.querySelectorAll("nav a");
window.addEventListener("scroll", e => {
scrollpos = window.scrollY;
navbarLinks.forEach(link => {
let section = document.querySelector(link.hash);
if (section.offsetTop <= scrollpos + 140 &&
section.offsetTop + section.offsetHeight > scrollpos + 130) {
link.classList.add("nav-link-active");
} else {
link.classList.remove("nav-link-active");
}
});
});
window.addEventListener('scroll',(e)=>{
const nav = document.querySelector('header');
if(window.pageYOffset>0){
nav.classList.add("add-shadow");
nav.classList.add("sticky");
}else{
nav.classList.remove("add-shadow");
nav.classList.add("sticky");
}
});