Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (72 loc) · 2.7 KB
/
Copy pathscript.js
File metadata and controls
89 lines (72 loc) · 2.7 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// gap for the nav bar
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
window.scrollTo({
top: target.offsetTop - 50, // Adjust the value as needed
behavior: 'smooth'
});
});
});
// Close sidebar when a nav link is clicked
document.querySelectorAll('.links-container a').forEach(function(link) {
link.addEventListener('click', function() {
document.getElementById('sidebar-active').checked = false;
});
});
// slideshow
let slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
let i;
let slides = document.getElementsByClassName("mySlides");
let dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
// accordion
document.addEventListener('DOMContentLoaded', function () {
const accordionHeaders = document.querySelectorAll('.accordion-header');
accordionHeaders.forEach(header => {
header.addEventListener('click', function () {
const content = this.nextElementSibling;
const icon = this.querySelector('.accordion-icon');
// Toggle the active class
this.classList.toggle('active');
// Toggle the max-height for the accordion content
if (content.style.maxHeight) {
content.style.maxHeight = null;
icon.textContent = '+';
} else {
content.style.maxHeight = content.scrollHeight + 'px';
icon.textContent = '×';
// Scroll to ensure the entire accordion content is centered in the viewport
setTimeout(() => {
const elementTop = this.getBoundingClientRect().top + window.scrollY;
const elementHeight = this.offsetHeight + content.scrollHeight;
const viewportHeight = window.innerHeight;
const scrollPosition = elementTop - (viewportHeight / 2) + (elementHeight / 2);
window.scrollTo({
top: scrollPosition,
behavior: 'smooth'
});
}, 50); // Delay to allow content expansion
}
});
});
});