@@ -332,10 +332,7 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
332
332
// https://bokand.github.io/viewport/index.html
333
333
let viewportWidth = window . visualViewport ?. width ?? innerWidth
334
334
let viewportHeight = window . visualViewport ?. height ?? innerHeight
335
-
336
- // Newer browsers supports scroll[X|Y], page[X|Y]Offset is
337
- let viewportX = window . scrollX ?? pageXOffset
338
- let viewportY = window . scrollY ?? pageYOffset
335
+ let { scrollX, scrollY } = window
339
336
340
337
let {
341
338
height : targetHeight ,
@@ -436,13 +433,13 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
436
433
blockScroll = targetBlock - viewportHeight
437
434
} else if ( block === 'nearest' ) {
438
435
blockScroll = alignNearest (
439
- viewportY ,
440
- viewportY + viewportHeight ,
436
+ scrollY ,
437
+ scrollY + viewportHeight ,
441
438
viewportHeight ,
442
439
borderTop ,
443
440
borderBottom ,
444
- viewportY + targetBlock ,
445
- viewportY + targetBlock + targetHeight ,
441
+ scrollY + targetBlock ,
442
+ scrollY + targetBlock + targetHeight ,
446
443
targetHeight
447
444
)
448
445
} else {
@@ -459,24 +456,23 @@ export let compute = (target: Element, options: Options): ScrollAction[] => {
459
456
} else {
460
457
// inline === 'nearest' is the default
461
458
inlineScroll = alignNearest (
462
- viewportX ,
463
- viewportX + viewportWidth ,
459
+ scrollX ,
460
+ scrollX + viewportWidth ,
464
461
viewportWidth ,
465
462
borderLeft ,
466
463
borderRight ,
467
- viewportX + targetInline ,
468
- viewportX + targetInline + targetWidth ,
464
+ scrollX + targetInline ,
465
+ scrollX + targetInline + targetWidth ,
469
466
targetWidth
470
467
)
471
468
}
472
469
473
470
// Apply scroll position offsets and ensure they are within bounds
474
471
// @TODO add more test cases to cover this 100%
475
- blockScroll = Math . max ( 0 , blockScroll + viewportY )
476
- inlineScroll = Math . max ( 0 , inlineScroll + viewportX )
472
+ blockScroll = Math . max ( 0 , blockScroll + scrollY )
473
+ inlineScroll = Math . max ( 0 , inlineScroll + scrollX )
477
474
} else {
478
475
// Handle each scrolling frame that might exist between the target and the viewport
479
-
480
476
if ( block === 'start' ) {
481
477
blockScroll = targetBlock - top - borderTop
482
478
} else if ( block === 'end' ) {
0 commit comments