-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
29 lines (24 loc) · 989 Bytes
/
scripts.js
File metadata and controls
29 lines (24 loc) · 989 Bytes
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
let currentTheme = 1;
const themes = ['theme1', 'theme2', 'theme3', 'theme4'];
function switchTheme() {
document.body.classList.remove(themes[currentTheme - 1]);
currentTheme = currentTheme % 4 + 1;
document.body.classList.add(themes[currentTheme - 1]);
}
document.addEventListener('DOMContentLoaded', function() {
const header = document.getElementById('header');
const links = document.querySelectorAll('a[href^="#"]');
for (const link of links) {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
const headerHeight = header.offsetHeight; // Get the height of the header
const targetPosition = targetElement.offsetTop - headerHeight; // Calculate the new scroll position
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
});
}
});