-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
61 lines (53 loc) · 1.85 KB
/
Copy pathscripts.js
File metadata and controls
61 lines (53 loc) · 1.85 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
let navMobile = document.getElementById('sidebar-mobile');
let navSidebar = document.getElementById('sidebar');
let hamburger = document.getElementById('hamburger');
let navActive = false;
navMobile.addEventListener('click',function(){
navSidebar.classList.toggle('active');
navActive = !navActive;
hamburger.innerHTML = navActive? "close" : "menu";
})
let typeText = document.getElementById("typewriter");
let options = ["fast learner", "Pythonist","Developer"]
let cursorPosition = 0;
let currnetIndex =0;
let speed = 100;
const typewriter=()=>{
typeText.innerText = options[currnetIndex].slice(0,cursorPosition);
if(cursorPosition++ < options[currnetIndex].length ) setTimeout(typewriter, speed);
else{
currnetIndex = (currnetIndex+1)%3;
cursorPosition=0;
setTimeout(typewriter,500);
}}
typewriter();
var anchorTags = document.querySelectorAll('a[href^="#"]');
for (let i=1;i<anchorTags.length;i++){
anchorTags[i].addEventListener('click', smoothScroll);
}
// Smooth scrolling function
function smoothScroll(e) {
e.preventDefault();
var targetId = this.getAttribute('href');
var targetElement = document.querySelector(targetId);
// Scroll smoothly to the target element
targetElement.scrollIntoView({ behavior: 'smooth' });
}
let contents = document.getElementsByClassName("sections");
let navLinks = document.getElementsByClassName('sideNav');
let contentWindow = document.getElementById("main-content");
let currentElementIndex = -1;
function setActive(){
for(let i=0;i<contents.length;i++){
if(contents[i].offsetTop <contentWindow.scrollTop){
currentElementIndex = i;
}
}
for(let i=0;i<navLinks.length;i++){
navLinks[i].classList.remove("nav-active");
}
if(currentElementIndex>=0){
navLinks[currentElementIndex].classList.add("nav-active");
}
}
contentWindow.addEventListener('scroll',setActive);