-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (27 loc) · 1.07 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
function scrollToElement(elementSelector, instance = 0) {
// Select all elements that match the given selector
const elements = document.querySelectorAll(elementSelector);
// Check if there are elements matching the selector and if the requested instance exists
if (elements.length > instance) {
// Scroll to the specified instance of the element
elements[instance].scrollIntoView({ behavior: 'smooth' });
}
}
const link1 = document.getElementById("link1");
const link2 = document.getElementById("link2");
const link3 = document.getElementById("link3");
const link4 = document.getElementById("link4");
link1.addEventListener('click', () => {
scrollToElement('.header');
});
link2.addEventListener('click', () => {
// Scroll to the second element with "header" class
scrollToElement('.header', 1);
});
link2.addEventListener('click', () => {
// Scroll to the second element with "header" class
scrollToElement('.header', 2);
});
link3.addEventListener('click', () => {
scrollToElement('.column');
});