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('mediawiki.util', function () {
const track = document.getElementById('everlightTrack');
if (!track) return;
const items = track.children;
let index = 0;
let autoScroll;
function scrollToIndex(i) {
const item = items[i];
if (!item) return;
const trackRect = track.getBoundingClientRect();
const itemRect = item.getBoundingClientRect();
const offset =
item.offsetLeft -
(trackRect.width / 2) +
(itemRect.width / 2);
track.scrollTo({ left: offset, behavior: 'smooth' });
}
function next() {
index = (index + 1) % items.length;
scrollToIndex(index);
}
function prev() {
index = (index - 1 + items.length) % items.length;
scrollToIndex(index);
}
document.getElementById('everlightNext')?.addEventListener('click', () => {
stopAuto();
next();
startAuto();
});
document.getElementById('everlightPrev')?.addEventListener('click', () => {
stopAuto();
prev();
startAuto();
});
function startAuto() {
autoScroll = setInterval(next, 4000); // 4 segundos
}
function stopAuto() {
clearInterval(autoScroll);
}
scrollToIndex(index);
startAuto();
});