export function volumeScroll(node, options = {}) { const { minVolume = 0, maxVolume = 1, sensitivity = 0.001, videoSelector = 'video', indicatorFadeDelay = 500, } = options; let video = document.querySelector(videoSelector); let indicator; let fadeTimeout; function createIndicator() { indicator = document.createElement('div'); indicator.style.cssText = ` position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; opacity: 0; transition: opacity 0.3s ease; pointer-events: none; background-color: rgba(0, 0, 0, 0.6); color: white; padding: 8px 12px; border-radius: 4px; font-family: Arial, sans-serif; font-size: 14px; `; indicator.innerHTML = ` 50% `; node.style.position = 'relative'; node.appendChild(indicator); } function updateIndicator(volume) { if (!indicator) createIndicator(); const percentage = Math.round(volume * 100); const volumeValue = indicator.querySelector('.volume-value'); volumeValue.textContent = `${percentage}%`; indicator.style.opacity = '1'; clearTimeout(fadeTimeout); fadeTimeout = setTimeout(() => { indicator.style.opacity = '0'; }, indicatorFadeDelay); } function handleWheel(e) { if (!video) return; const volumeChange = e.deltaY * sensitivity; let newVolume = video.volume - volumeChange; newVolume = Math.max(minVolume, Math.min(maxVolume, newVolume)); video.volume = newVolume; updateIndicator(newVolume); // Prevent default scrolling behavior e.preventDefault(); } createIndicator(); node.addEventListener('wheel', handleWheel, { passive: false }); return { destroy() { node.removeEventListener('wheel', handleWheel); if (indicator && indicator.parentNode) { indicator.parentNode.removeChild(indicator); } clearTimeout(fadeTimeout); } }; }