我需要一些帮助。
我尝试使用相同的类(.section-container)定位多个 div 的 Y 坐标,
但 console.log 为每个 div 返回 0。
(2) [div.section-container, div.section-container] 2 0
你有什么想法吗?
const sectionSelector = element !== undefined
? element.querySelectorAll('.section-container')
: false;
const sectionArr = Array.from(sectionSelector);
const PosY = function()
{
sectionArr.forEach( function(e)
{
const pos = e.getBoundingClientRect();
const y = pos.top;
console.log(y)
})
}
PosY();
谢谢你的帮助!