|
|
第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);
| |