how to get offset from top js code example
Example 1: javascript get element position relative to document
element.getBoundingClientRect().top + document.documentElement.scrollTop
Example 2: offset in js
var d = document.getElementById("div1");
var topPos = d.offsetTop;
if (topPos > 10) {
// object is offset more
// than 10 pixels from its parent
}