如何判斷元素是否到達可視區(qū)域?
2022-10-26 09:35 作者:網(wǎng)星軟件 | 我要投稿
如何判斷元素是否到達可視區(qū)域?
以圖片顯示為例:
1.window.innerHeight
是瀏覽器可視區(qū)的高度;
2.document.body.scrollTop || document.documentElement.scrollTop
是瀏覽器滾動的過的距離;
3.imgs.offsetTop
是元素頂部距離文檔頂部的高度(包括滾動條的距離);
4.內(nèi)容達到顯示區(qū)域的:img.offsetTop < window.innerHeight + document.body.scrollTop;

標簽: