-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
43 lines (36 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
34
35
36
37
38
39
40
41
42
43
const imgs = document.getElementById('img');
const img = document.querySelectorAll('#img img');
let idx = 0;
let interval = setInterval(carousel, 3000);
function carousel() {
idx++;
if (idx >= img.length) {
idx = 0;
}
const translateXValue = -(idx * (100 / img.length));
imgs.style.transform = `translateX(${translateXValue}%)`;
}
imgs.addEventListener('mouseenter', () => {
clearInterval(interval);
});
imgs.addEventListener('mouseleave', () => {
interval = setInterval(carousel, 3000);
});
// Alternar Tema
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark-mode');
if (body.classList.contains('dark-mode')) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
});
// Carregar Tema
document.addEventListener('DOMContentLoaded', () => {
const theme = localStorage.getItem('theme');
if (theme === 'dark') {
body.classList.add('dark-mode');
}
});