discourse/app/assets/javascripts/discourse-common/addon/utils/dom-utils.js
Joffrey JAFFEUX bec76f937c
DEV: drops jquery from scrolling-post-stream (#15313)
Note that this commit also introduces a `domUtils` helper to handle most complex operations in vanilla JS compared to using jQuery.
2021-12-17 14:52:42 +01:00

22 lines
566 B
JavaScript

function offset(element) {
// note that getBoundingClientRect forces a reflow.
// When used in critical performance conditions
// you might want to move to more involved solution
// such as implementing an IntersectionObserver and
// using its boundingClientRect property
const rect = element.getBoundingClientRect();
return {
top: rect.top + window.scrollY,
left: rect.left + window.scrollX,
};
}
function position(element) {
return {
top: element.offsetTop,
left: element.offsetLeft,
};
}
export default { offset, position };