MediaWiki:Common.js
Nota: Após publicar, você pode ter que limpar o "cache" do seu navegador para ver as alterações.
- Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
- Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
- Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
- Opera: Pressione Ctrl-F5.
mw.loader.using('jquery', function () {
const $carousel = $('.carousel-wrapper');
const $items = $('.carousel-item');
let index = 0;
function update() {
const itemWidth = $items.outerWidth(true);
$carousel.scrollLeft(index * itemWidth);
$items.removeClass('active');
$items.eq(index).addClass('active');
}
$('.right-btn').on('click', function () {
index = (index + 1) % $items.length;
update();
});
$('.left-btn').on('click', function () {
index = (index - 1 + $items.length) % $items.length;
update();
});
setInterval(function () {
index = (index + 1) % $items.length;
update();
}, 4000);
update();
});
mw.loader.using('jquery', function () {
const wrapper = document.querySelector('.everlight-carousel .carousel-wrapper');
const items = document.querySelectorAll('.everlight-carousel .carousel-item');
const next = document.querySelector('.right-btn');
const prev = document.querySelector('.left-btn');
let current = 0;
function updateCarousel() {
items.forEach((item, index) => {
item.classList.toggle('active', index === current);
});
const activeItem = items[current];
const wrapperRect = wrapper.getBoundingClientRect();
const itemRect = activeItem.getBoundingClientRect();
const scrollPosition =
activeItem.offsetLeft -
(wrapperRect.width / 2) +
(itemRect.width / 2);
wrapper.scrollTo({
left: scrollPosition,
behavior: 'smooth'
});
}
next.onclick = () => {
if (current < items.length - 1) {
current++;
updateCarousel();
}
};
prev.onclick = () => {
if (current > 0) {
current--;
updateCarousel();
}
};
// Centraliza o primeiro ao carregar
updateCarousel();
});