fix: btn position when window resizes

This commit is contained in:
Xmader 2020-12-31 13:13:26 -05:00
parent 8e0ce90093
commit bb39ebccc9
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
1 changed files with 14 additions and 7 deletions

View File

@ -104,6 +104,16 @@ export class BtnList {
return btnTpl
}
private _positionBtns (newParent: HTMLDivElement) {
try {
const anchorDiv = this.getBtnParent()
const { top } = anchorDiv.getBoundingClientRect()
newParent.style.top = `${top}px`
} catch (err) {
console.error(err)
}
}
private _commit () {
const btnParent = document.querySelector('div') as HTMLDivElement
const shadow = attachShadow(btnParent)
@ -121,13 +131,10 @@ export class BtnList {
newParent.append(...this.list.map(e => cloneBtn(e)))
shadow.append(newParent)
try {
const anchorDiv = this.getBtnParent()
const { top } = anchorDiv.getBoundingClientRect()
newParent.style.top = `${top}px`
} catch (err) {
console.error(err)
}
const pos = () => this._positionBtns(newParent)
pos()
document.addEventListener('readystatechange', pos)
window.addEventListener('resize', pos)
return btnParent
}