Add correction to offset of imposter rect

Necessary when dealing with CSS transforms
This commit is contained in:
toasted-nutbread 2019-10-17 19:30:54 -04:00
parent 8f918c63dc
commit a5d7de8e97

View File

@ -27,8 +27,8 @@ function docImposterCreate(element, isTextarea) {
const elementStyle = window.getComputedStyle(element); const elementStyle = window.getComputedStyle(element);
const elementRect = element.getBoundingClientRect(); const elementRect = element.getBoundingClientRect();
const documentRect = document.documentElement.getBoundingClientRect(); const documentRect = document.documentElement.getBoundingClientRect();
const left = elementRect.left - documentRect.left; let left = elementRect.left - documentRect.left;
const top = elementRect.top - documentRect.top; let top = elementRect.top - documentRect.top;
// Container // Container
const container = document.createElement('div'); const container = document.createElement('div');
@ -82,6 +82,12 @@ function docImposterCreate(element, isTextarea) {
docSetImposterStyle(imposterStyle, 'width', `${width}px`); docSetImposterStyle(imposterStyle, 'width', `${width}px`);
docSetImposterStyle(imposterStyle, 'height', `${height}px`); docSetImposterStyle(imposterStyle, 'height', `${height}px`);
} }
if (imposterRect.x !== elementRect.x || imposterRect.y !== elementRect.y) {
left += (elementRect.left - imposterRect.left);
top += (elementRect.top - imposterRect.top);
docSetImposterStyle(imposterStyle, 'left', `${left}px`);
docSetImposterStyle(imposterStyle, 'top', `${top}px`);
}
imposter.scrollTop = element.scrollTop; imposter.scrollTop = element.scrollTop;
imposter.scrollLeft = element.scrollLeft; imposter.scrollLeft = element.scrollLeft;