MediaWiki:Common.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ const container = document.getElementById('Homepage_scrollContainer'); let scrollInterval; function startScrolling() { const items = document.querySelectorAll('.scroll-item'); scrollInterval = setInterval(() => { items.forEach(item => { const currentTransform = getComputedStyle(item).transform; const matrixValues = currentTransform.match(/matrix.*\((.+)\)/); const translateXValue = matrixValues ? parseFloat(matrixValues[1].split(', ')[4]) : 0; // Move item to the left item.style.transform = `translateX(${translateXValue - 1}px)`; // If item moves out of view, reset its position if (translateXValue <= -item.offsetWidth) { item.style.transform = `translateX(${container.offsetWidth}px)`; } }); }, 10); // Adjust speed by changing the interval time } function stopScrolling() { clearInterval(scrollInterval); } // Start scrolling when the page loads startScrolling(); // Stop scrolling on mouse over container.addEventListener('mouseover', stopScrolling); // Resume scrolling on mouse out container.addEventListener('mouseout', startScrolling);