There is ceiling tabBar which represent different part of my page and i try to get each part‘s offsetTop in componentDidMount, then i can switch the tabBar by comparing the document.element.scrollTop to the offsetTop. However i found that i can't get the correct offsetTop of each part in componengtDidMount,since elements didn't being fully rendered.
here are some relative code
const tabList = [
{
title: 'xxxx1',
id: 'feature',
offsetTop: 0
},
{
title: 'xxxx2',
id: 'compensation',
offsetTop: 0
},
{
title: 'xxxx3',
id: 'faq',
offsetTop: 0
},
{
title: 'xxxx4',
id: 'form',
offsetTop: 0
}
]
componentDidMount() {
this.getEleOffsetTop()
}
getEleOffsetTop = () => {
tabList.forEach(item => {
let node = document.getElementById(`${item.id}`)
if (node) {
item.offsetTop = node.offsetTop
}
})
console.log('tabList', tabList)
}