Skip to content

Commit ee5bc06

Browse files
author
illarionov-company
committed
change window.innerHeight to dirty-hack Globals.screenHeight
1 parent f0c9a46 commit ee5bc06

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src-lib/engine/Driver.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class Driver {
102102
updateLimits() {
103103
this.start.updateLimits()
104104
this.end.updateLimits()
105-
if (this.end.top < this.start.top) this.end.top += window.innerHeight
105+
if (this.end.top < this.start.top) this.end.top += Globals.screenHeight
106106
this.helper.updateLimits()
107107

108108
for (let property of this.properties) {
@@ -210,7 +210,7 @@ export class DriverBorder {
210210
updateLimits() {
211211
this.top = this.domElement.getBoundingClientRect().top + Globals.scroll
212212

213-
if (this.edge === "bottom") this.top -= window.innerHeight
213+
if (this.edge === "bottom") this.top -= Globals.screenHeight
214214
}
215215
}
216216

@@ -247,8 +247,8 @@ export class DriverHelper {
247247
let top = this.driver.start.top
248248
let end = this.driver.end.top
249249

250-
if (this.driver.start.edge === "bottom") top += window.innerHeight
251-
if (this.driver.end.edge === "bottom") end += window.innerHeight
250+
if (this.driver.start.edge === "bottom") top += Globals.screenHeight
251+
if (this.driver.end.edge === "bottom") end += Globals.screenHeight
252252

253253
this.domElement.style.setProperty("top", top + "px")
254254
this.domElement.style.setProperty("height", end - top + "px")

src-lib/engine/TheSuperSonicPluginForScrollBasedAnimation.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export class TheSuperSonicPluginForScrollBasedAnimation {
8787

8888
/** Updates global scroll and driver DOM elements top offset. Called once on page load and each time after window.resize */
8989
updateLimits() {
90+
this.updateScreenHeight()
9091
this.updateScroll()
9192
Driver.updateLimits()
9293

@@ -99,6 +100,27 @@ export class TheSuperSonicPluginForScrollBasedAnimation {
99100
window.scrollY || window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
100101
}
101102

103+
/** Dirty hack for calculating screen height. We can't just use "window.innerHeight" because it "jumps" on mobile phones when you scroll and toolbar collapses */
104+
updateScreenHeight() {
105+
const styles = {
106+
position: "absolute",
107+
left: "0",
108+
top: "0",
109+
height: "100vh",
110+
width: "1px",
111+
zIndex: "-1",
112+
visibility: "hidden",
113+
}
114+
let helper = document.createElement("div")
115+
for (let property in styles) {
116+
// @ts-ignore
117+
helper.style.setProperty(property, styles[property])
118+
}
119+
document.body.appendChild(helper)
120+
Globals.screenHeight = helper.clientHeight // it is a dirty hack because this line causes a reflow
121+
helper.remove()
122+
}
123+
102124
/** Add event listeners */
103125
addEventListeners() {
104126
this.onResize = () => {

src-lib/singletons/Globals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Globals: Globals = {
22
scroll: 0,
3+
screenHeight: 0,
34
rafActive: true,
45
rafId: 0,
56
renderedInitially: false,

src-lib/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ type _Element = import("./engine/Element").Element
22

33
interface Globals {
44
scroll: number
5+
screenHeight: number
56
rafActive: boolean
67
rafId: number
78
renderedInitially: boolean

0 commit comments

Comments
 (0)