 const paragraphs = document.querySelectorAll('div[dh]'); const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { console.log('entry', `${entry.target.getAttribute('dh')}`, entry.boundingClientRect.y); }); }); paragraphs.forEach((paragraph) => { observer.observe(paragraph); }); 距离顶部距离,都为正数时取最小值,都为负数时取最大值,存在正负数时,取负数最大值