Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit bdf8c18

Browse files
authored
Merge pull request #126 from alexfoxy/bug/AF01/pass-frame-to-getValueFn
Bug: AF01 - pass frame to get value fn
2 parents 362595b + c84a79b commit bdf8c18

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/lax.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,17 @@
267267
return flattenedStyles
268268
}
269269

270+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY#Notes
271+
function getScrollPosition() {
272+
const supportPageOffset = window.pageXOffset !== undefined
273+
const isCSS1Compat = ((document.compatMode || '') === 'CSS1Compat')
274+
275+
const x = supportPageOffset ? window.pageXOffset : isCSS1Compat ? document.documentElement.scrollLeft : document.body.scrollLeft
276+
const y = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop
277+
278+
return [y, x]
279+
}
280+
270281
function parseValue(val, { width, height, x, y }, index) {
271282
if (typeof val === 'number') {
272283
return val
@@ -276,8 +287,7 @@
276287
const pageWidth = document.body.scrollWidth
277288
const screenWidth = window.innerWidth
278289
const screenHeight = window.innerHeight
279-
const scrollTop = window.scrollY
280-
const scrollLeft = window.scrollX
290+
const [scrollTop, scrollLeft] = getScrollPosition()
281291

282292
const left = x + scrollLeft
283293
const right = left + width
@@ -321,14 +331,14 @@
321331
this[key] = options[key]
322332
})
323333

324-
this.lastValue = this.getValueFn()
334+
this.lastValue = this.getValueFn(0)
325335
}
326336

327337
getValue = (frame) => {
328338
let value = this.lastValue
329339

330340
if (frame % this.frameStep === 0) {
331-
value = this.getValueFn()
341+
value = this.getValueFn(frame)
332342
}
333343

334344
if (this.inertiaEnabled) {

0 commit comments

Comments
 (0)