This gives you an offset relative to your client viewport, meaning that if you scroll the item and see, then you can check the difference.
pen
console.log('offsetTop: ' + elem.offsetTop); //This is fixed.
console.log('getBoundingClientRect: ' + elem.getBoundingClientRect().top); // this is changing while scroll
see pen, scroll through the list and check the console.
source
share