Skip to content

Instantly share code, notes, and snippets.

View endersaka's full-sized avatar
😊

endersaka endersaka

😊
View GitHub Profile
@endersaka
endersaka / get_html_element_coords.js
Created April 25, 2020 08:14
Get HTML element position relative to document space
function getElementCoordinates(el) {
const doc = document.documentElement;
const scrollLeft = window.pageXOffset || doc.scrollLeft;
const scrollTop = window.pageYOffset || doc.scrollTop;
const rect = el.getBoundingClientRect();
return {
top: rect.top + scrollTop,
left: rect.left + scrollLeft
}
}