fix: btn position when window resizes
This commit is contained in:
parent
8e0ce90093
commit
bb39ebccc9
1 changed files with 14 additions and 7 deletions
21
src/btn.ts
21
src/btn.ts
|
@ -104,6 +104,16 @@ export class BtnList {
|
||||||
return btnTpl
|
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 () {
|
private _commit () {
|
||||||
const btnParent = document.querySelector('div') as HTMLDivElement
|
const btnParent = document.querySelector('div') as HTMLDivElement
|
||||||
const shadow = attachShadow(btnParent)
|
const shadow = attachShadow(btnParent)
|
||||||
|
@ -121,13 +131,10 @@ export class BtnList {
|
||||||
newParent.append(...this.list.map(e => cloneBtn(e)))
|
newParent.append(...this.list.map(e => cloneBtn(e)))
|
||||||
shadow.append(newParent)
|
shadow.append(newParent)
|
||||||
|
|
||||||
try {
|
const pos = () => this._positionBtns(newParent)
|
||||||
const anchorDiv = this.getBtnParent()
|
pos()
|
||||||
const { top } = anchorDiv.getBoundingClientRect()
|
document.addEventListener('readystatechange', pos)
|
||||||
newParent.style.top = `${top}px`
|
window.addEventListener('resize', pos)
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return btnParent
|
return btnParent
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue