-
Notifications
You must be signed in to change notification settings - Fork 0
/
js[withTimer].js
36 lines (32 loc) · 946 Bytes
/
js[withTimer].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
34
35
36
const tabs = document.querySelector(".tabs")
const item = tabs.querySelector(".tabpage")
const items = tabs.querySelectorAll(".tabpage")
const list = tabs.querySelector(".tabheaditem")
const lists = tabs.querySelectorAll(".tabheaditem")
item.classList.add("show")
list.classList.add("active")
let timeout = 0;
if (lists.length != items.length) {
alert("The number of tabs does not match the number of pages.")
}
for ( i = lists.length -1 ; ~i!=0 ; i-- ) {
lists[i].setAttribute("onclick", "makemeshow(" + i + ")")
}
function makemeshow (t) {
tabs.querySelector(".show").classList.remove("show");
items[t].classList.add("show")
tabs.querySelector(".active").classList.remove("active");
lists[t].classList.add("active")
timeout = t;
}
function timer() {
if (timeout >= lists.length) {
timeout = 0;
timer()
} else {
makemeshow(timeout)
timeout++
window.setTimeout(timer, 5000)
}
}
timer()