MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 1: | Linha 1: | ||
const carousel = document.getElementById('carousel'); | |||
const cards = document.querySelectorAll('.card'); | |||
const nextBtn = document.getElementById('nextBtn'); | |||
const prevBtn = document.getElementById('prevBtn'); | |||
let currentIndex = 2; // Começa com o terceiro card centralizado | |||
const cardWidth = cards[0].offsetWidth + 20; // Largura + Gap | |||
// Função para centralizar o card | |||
function updateCarousel() { | |||
carousel.scrollTo({ | |||
left: (currentIndex - 1) * cardWidth, | |||
behavior: 'smooth' | |||
}); | |||
// Atualizar classe active | |||
cards.forEach((card, index) => { | |||
if ( | card.classList.remove('active'); | ||
if (index === currentIndex) { | |||
card.classList.add('active'); | |||
} | |||
}); | |||
} | |||
// Navegação | |||
nextBtn.addEventListener('click', () => { | |||
if (currentIndex < cards.length - 1) { | |||
currentIndex++; | |||
updateCarousel(); | |||
} | } | ||
}); | |||
prevBtn.addEventListener('click', () => { | |||
if (currentIndex > 0) { | |||
currentIndex--; | |||
updateCarousel(); | |||
} | } | ||
}); | |||
// Auto Slide (a cada 3 segundos) | |||
setInterval(() => { | |||
if (currentIndex < cards.length - 1) { | |||
currentIndex++; | |||
} else { | |||
currentIndex = 0; // Volta ao início | |||
} | |||
} | } | ||
updateCarousel(); | |||
}, 3000); | |||
// Iniciar centralizado | |||
updateCarousel(); | |||
<script src="script.js"></script> | |||
Edição das 21h33min de 16 de janeiro de 2026
const carousel = document.getElementById('carousel');
const cards = document.querySelectorAll('.card');
const nextBtn = document.getElementById('nextBtn');
const prevBtn = document.getElementById('prevBtn');
let currentIndex = 2; // Começa com o terceiro card centralizado
const cardWidth = cards[0].offsetWidth + 20; // Largura + Gap
// Função para centralizar o card
function updateCarousel() {
carousel.scrollTo({
left: (currentIndex - 1) * cardWidth,
behavior: 'smooth'
});
// Atualizar classe active
cards.forEach((card, index) => {
card.classList.remove('active');
if (index === currentIndex) {
card.classList.add('active');
}
});
}
// Navegação
nextBtn.addEventListener('click', () => {
if (currentIndex < cards.length - 1) {
currentIndex++;
updateCarousel();
}
});
prevBtn.addEventListener('click', () => {
if (currentIndex > 0) {
currentIndex--;
updateCarousel();
}
});
// Auto Slide (a cada 3 segundos)
setInterval(() => {
if (currentIndex < cards.length - 1) {
currentIndex++;
} else {
currentIndex = 0; // Volta ao início
}
updateCarousel();
}, 3000);
// Iniciar centralizado
updateCarousel();
<script src="script.js"></script>