let box = document.getElementById(‘div’); // 獲取元素
alert(box.getBoundingClientRect().top); // 元素上邊距離頁面上邊的距離
alert(box.getBoundingClientRect().right); // 元素右邊距離頁面左邊的距離
alert(box.getBoundingClientRect().bottom); // 元素下邊距離頁面上邊的距離文章來源:http://www.zghlxwxcb.cn/news/detail-457568.html
alert(box.getBoundingClientRect().left); // 元素左邊距離頁面左邊的距離文章來源地址http://www.zghlxwxcb.cn/news/detail-457568.html
到了這里,關(guān)于獲取div到頂部的距離的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!