-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
126 lines (95 loc) · 3.16 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// header
const header = document.querySelector("header");
window.addEventListener("scroll", function(){
header.classList.toggle("sticky", window.scrollY > 100);
});
// navlist
let menu = document.querySelector("#menu-icon");
let navlist = document.querySelector(".navlist");
menu.onclick = () => {
menu.classList.toggle('bx-x');
navlist.classList.toggle('open');
};
window.onscroll = () => {
menu.classList.remove('bx-x');
navlist.classList.remove('open');
};
// active section of the page
// Get all the links in the navbar
const navLinks = document.querySelectorAll('.navlist a');
// Add an event listener to the scroll event
window.addEventListener('scroll', function() {
const scrollPosition = window.pageYOffset;
// Iterate over each section and check if it is in the viewport
document.querySelectorAll('section').forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (scrollPosition >= sectionTop - 100 && scrollPosition < sectionTop + sectionHeight) {
const targetLink = document.querySelector(`.navlist a[href="#${section.id}"]`);
// Remove the 'active' class from all links
navLinks.forEach(link => link.classList.remove('active'));
// Add the 'active' class to the target link
if (targetLink) {
targetLink.classList.add('active');
}
}
});
});
// read more
/* commented coz I have removed the section for a while
const serviceItems = document.querySelectorAll('.read');
const read_da = document.querySelector('#data-analysis');
const read_ml = document.querySelector('#machine-learning');
const read_dl = document.querySelector('#deep-learning');
serviceItems.forEach(item => {
item.addEventListener('click', function() {
if(item.id === 'read-da'){
read_da.style.display = 'block';
}
else if(item.id === 'read-ml'){
read_ml.style.display = 'block';
}
else{
read_dl.style.display = 'block';
}
});
});
read_da.addEventListener('click', function(e) {
if (e.target === read_da) {
read_da.style.display = 'none';
}
});
read_ml.addEventListener('click', function(e) {
if (e.target === read_ml) {
read_ml.style.display = 'none';
}
});
read_dl.addEventListener('click', function(e) {
if (e.target === read_dl) {
read_dl.style.display = 'none';
}
});
*/
// remove the background image, for the project boxes
const layerDivs = document.querySelectorAll('.row');
layerDivs.forEach(layerDiv => {
const image = layerDiv.querySelector('.project-img');
layerDiv.addEventListener('mouseenter', function() {
image.classList.add('hide');
layerDiv.classList.add('hide');
});
layerDiv.addEventListener('mouseleave', function() {
image.classList.remove('hide');
layerDiv.classList.remove('hide');
});
});
// jump between multiple pages
function navigateToPage(url) {
window.location.href = url;
}
// to prevent page scrolling when we use arrow keys to play the game
document.addEventListener('keydown', function(event) {
if (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
event.preventDefault();
}
});