-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
61 lines (52 loc) · 1.77 KB
/
scripts.js
File metadata and controls
61 lines (52 loc) · 1.77 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
document.querySelectorAll('.nav a').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
});
});
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
// Check for partial visibility: Any part of the element is visible
return (
rect.top <= window.innerHeight &&
rect.bottom >= 0
);
}
// Function to handle scroll event
function handleScroll() {
var elements = document.querySelectorAll('.div-to-scroll');
elements.forEach(function(el) {
if (isElementInViewport(el)) {
el.classList.add('visible');
} else {
el.classList.remove('visible');
}
});
}
// Initial check on page load
document.addEventListener('DOMContentLoaded', handleScroll);
// Check on scroll
document.addEventListener('scroll', handleScroll);
function toggleSemester(semesterId) {
var content = document.getElementById(semesterId);
if (content.style.maxHeight) {
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
}
// Select all project items
const projectItems = document.querySelectorAll('.project-item');
// Add click event listener to each project item
projectItems.forEach(item => {
const heading = item.querySelector('.heading');
const description = item.querySelector('.description');
// Toggle description visibility on heading click
heading.addEventListener('click', () => {
description.classList.toggle('show');
});
});