-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtabs.js
More file actions
20 lines (19 loc) · 700 Bytes
/
tabs.js
File metadata and controls
20 lines (19 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
document.addEventListener("DOMContentLoaded", () => {
let tabs = document.querySelectorAll(".tabs h3");
let tabContents = document.querySelectorAll(" .tab-content .hidden");
tabs.forEach((tab, index) => {
tab.addEventListener("click", (e) => {
tabs.forEach((tab) => {
tab.classList.remove("active");
});
tab.classList.add("active");
let line = document.querySelector(".tabs .line");
line.style.width = e.target.offsetWidth + "px";
line.style.left = e.target.offsetLeft + "px";
tabContents.forEach((content, index) => {
content.classList.remove("active");
})
tabContents[index].classList.add('active');
});
});
});