* * @param {HTMLElement} $el
($el)
| 267 | * @param {HTMLElement} $el |
| 268 | */ |
| 269 | constructor($el) { |
| 270 | this.$el = $el; |
| 271 | |
| 272 | this.onhide = this.onhide.bind(this); |
| 273 | this.onshow = this.onshow.bind(this); |
| 274 | |
| 275 | this.$replacement = <span className="page-replacement"></span>; |
| 276 | this.$replacement.handler = this; |
| 277 | |
| 278 | this.$el.on("hide", this.onhide); |
| 279 | this.$el.on("show", this.onshow); |
| 280 | |
| 281 | // Cache scroll position on scroll event to prevent synchronous layout reading (forced reflow) during page transitions |
| 282 | this.$el.addEventListener( |
| 283 | "scroll", |
| 284 | (e) => { |
| 285 | const $body = this.$el.body; |
| 286 | if ($body && e.target === $body) { |
| 287 | this.scrollLeft = $body.scrollLeft; |
| 288 | this.scrollTop = $body.scrollTop; |
| 289 | } |
| 290 | }, |
| 291 | { capture: true, passive: true }, |
| 292 | ); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * Replace current element with a replacement element |