(function(){ class SPZCustomContinueWatching extends SPZ.BaseElement { constructor(element) { super(element); this.isExecuted = false; } isLayoutSupported(layout) { return layout === SPZCore.Layout.LOGIC; } buildCallback(){ this.registerAction('finish', (invocation) => { this.finish(); }); } finish () { const sortFixedItems = () => { const fixedItems = document.querySelectorAll('.bs-home-fixed-item'); if (!fixedItems) return; const isPC = window.matchMedia('(min-width: 960px)').matches; // 是否为PC端 const gap = isPC ? 20 : 12; // 间距 let countHeight = 20; const fixedItemsArray = Array.from(fixedItems); const fixedItemsArraySorted = fixedItemsArray.sort((a, b) => Number(a.dataset.index) - Number(b.dataset.index)).filter(dom => dom.offsetHeight > 0); fixedItemsArraySorted.forEach((dom) => { dom.style.bottom = `${countHeight}px`; countHeight += dom.offsetHeight + gap; }); }; if (this.isExecuted) return; sortFixedItems(); this.isExecuted = true; this.bindEvent(sortFixedItems); } bindEvent(cb) { let lastScrollY = 0; let scrollTimeout = null; const container = document.querySelector('.continue-watching-container-single'); if (!container) return; const action = container.querySelector('.action'); const scrollHandler = () => { const currentScrollY = window.scrollY; const scrollDelta = currentScrollY - lastScrollY; // 清除之前的定时器 if (scrollTimeout) { clearTimeout(scrollTimeout); } // 滚动时隐藏浮窗 if (Math.abs(scrollDelta) >= 2) { if (container) { container.classList.add('cw-single-slide-out'); } } // 停止滚动后检查是否应该显示浮窗 scrollTimeout = setTimeout(() => { if (container) { container.classList.remove('cw-single-slide-out'); } }, 500); lastScrollY = currentScrollY; }; const handler = () => { container.parentElement.removeChild(container); window.removeEventListener('scroll', scrollHandler); cb?.(); }; window.addEventListener('scroll', scrollHandler); action.removeEventListener('click', handler); action.addEventListener('click', handler); } } SPZ.defineElement('spz-custom-continue-watching', SPZCustomContinueWatching); })()