-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
72 lines (58 loc) · 1.58 KB
/
Copy pathindex.js
File metadata and controls
72 lines (58 loc) · 1.58 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
const btnMcmods = document.getElementById("btn-mcmods");
const btnPics = document.getElementById("btn-pics");
const btnNetawork = document.getElementById("btn-netawork");
const slides = document.querySelectorAll('.banner');
let currentIndex = 0;
function updateCarousel() {
const offset = -currentIndex * 100; // 每页100%
slides.forEach(slide => {
slide.style.transform = `translateX(${offset}%)`;
});
}
function showNext() {
currentIndex = (currentIndex + 1) % slides.length;
updateCarousel();
}
function showPrev() {
currentIndex = (currentIndex - 1 + slides.length) % slides.length;
updateCarousel();
}
btnMcmods.addEventListener("mouseenter", () => {
currentIndex = 0;
updateCarousel();
resetAutoplay();
});
btnPics.addEventListener("mouseenter", () => {
currentIndex = 1;
updateCarousel();
resetAutoplay();
});
btnNetawork.addEventListener("mouseenter", () => {
currentIndex = 2;
updateCarousel();
resetAutoplay();
});
let timer = null;
function startAutoplay() {
timer = setInterval(showNext, 10000);
}
function resetAutoplay() {
clearInterval(timer);
startAutoplay();
}
startAutoplay();
// Header buttons
btnMcmods.addEventListener("click", () => {
window.location.href = "./mcmods.html";
});
// Arrows
const nextButton = document.getElementById("next-button");
const previousButton = document.getElementById("previous-button");
nextButton.addEventListener("click", () => {
showNext();
resetAutoplay();
});
previousButton.addEventListener("click", () => {
showPrev();
resetAutoplay();
});