@@ -141,20 +141,40 @@ import {
141141 const yPercent = yMax . unit === '%' || yMin . unit === '%' ;
142142 const xPercent = xMax . unit === '%' || xMin . unit === '%' ;
143143
144- const h100 = elHeight / 100 ;
145- const yMaxPx = yPercent ? ( yMax . value * h100 ) : yMax . value ;
146- const yMinPx = yPercent ? ( yMin . value * h100 ) : yMin . value ; // negative value
144+ // X offsets
145+ let yMinPx = yMin . value ;
146+ let yMaxPx = yMax . value ;
147+
148+ if ( yPercent ) {
149+ const h100 = elHeight / 100 ;
150+ yMaxPx = yMax . value * h100 ;
151+ yMinPx = yMin . value * h100 ; // negative value
152+ }
153+
154+ // Y offsets
155+ let xMinPx = xMax . value ;
156+ let xMaxPx = xMin . value ;
147157
148- const w100 = elWidth / 100 ;
149- const xMaxPx = xPercent ? ( xMax . value * w100 ) : xMax . value ;
150- const xMinPx = xPercent ? ( xMin . value * w100 ) : xMin . value ; // negative value
158+ if ( xPercent ) {
159+ const w100 = elWidth / 100 ;
160+ xMaxPx = xMax . value * w100 ;
161+ xMinPx = xMin . value * w100 ; // negative value
162+ }
151163
152164 // NOTE: must add the current scroll position when the
153165 // element is checked so that we get its absolute position
154166 // relative to the document and not the viewport then
155167 // add the min/max offsets calculated above
156- const top = rect . top + scrollY + ( slowerScrollRate ? yMinPx : yMaxPx * - 1 ) ;
157- const bottom = rect . bottom + scrollY + ( slowerScrollRate ? yMaxPx : yMinPx * - 1 ) ;
168+ let top = 0 ;
169+ let bottom = 0 ;
170+
171+ if ( slowerScrollRate ) {
172+ top = rect . top + scrollY + yMinPx ;
173+ bottom = rect . bottom + scrollY + yMaxPx ;
174+ } else {
175+ top = rect . top + scrollY + ( yMaxPx * - 1 ) ;
176+ bottom = rect . bottom + scrollY + ( yMinPx * - 1 ) ;
177+ }
158178
159179 // Total distance the element will move from when
160180 // the top enters the view to the bottom leaving
0 commit comments