File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ export class Driver {
102
102
updateLimits ( ) {
103
103
this . start . updateLimits ( )
104
104
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
106
106
this . helper . updateLimits ( )
107
107
108
108
for ( let property of this . properties ) {
@@ -210,7 +210,7 @@ export class DriverBorder {
210
210
updateLimits ( ) {
211
211
this . top = this . domElement . getBoundingClientRect ( ) . top + Globals . scroll
212
212
213
- if ( this . edge === "bottom" ) this . top -= window . innerHeight
213
+ if ( this . edge === "bottom" ) this . top -= Globals . screenHeight
214
214
}
215
215
}
216
216
@@ -247,8 +247,8 @@ export class DriverHelper {
247
247
let top = this . driver . start . top
248
248
let end = this . driver . end . top
249
249
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
252
252
253
253
this . domElement . style . setProperty ( "top" , top + "px" )
254
254
this . domElement . style . setProperty ( "height" , end - top + "px" )
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ export class TheSuperSonicPluginForScrollBasedAnimation {
87
87
88
88
/** Updates global scroll and driver DOM elements top offset. Called once on page load and each time after window.resize */
89
89
updateLimits ( ) {
90
+ this . updateScreenHeight ( )
90
91
this . updateScroll ( )
91
92
Driver . updateLimits ( )
92
93
@@ -99,6 +100,27 @@ export class TheSuperSonicPluginForScrollBasedAnimation {
99
100
window . scrollY || window . pageYOffset || document . documentElement . scrollTop || document . body . scrollTop
100
101
}
101
102
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
+
102
124
/** Add event listeners */
103
125
addEventListeners ( ) {
104
126
this . onResize = ( ) => {
Original file line number Diff line number Diff line change 1
1
const Globals : Globals = {
2
2
scroll : 0 ,
3
+ screenHeight : 0 ,
3
4
rafActive : true ,
4
5
rafId : 0 ,
5
6
renderedInitially : false ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ type _Element = import("./engine/Element").Element
2
2
3
3
interface Globals {
4
4
scroll : number
5
+ screenHeight : number
5
6
rafActive : boolean
6
7
rafId : number
7
8
renderedInitially : boolean
You can’t perform that action at this time.
0 commit comments