MediaWiki:Common.js:修订间差异
跳转到导航
跳转到搜索
页面内容被替换为“→这里的任何JavaScript将为所有用户在每次页面加载时加载。:” 标签:替换 |
无编辑摘要 标签:已被回退 |
||
第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ | /* 这里的任何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); |
2024年10月30日 (三) 21:11的版本
/* 这里的任何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);