Skip to content

Commit c99d96a

Browse files
fix: correct scroll distance when frame in a scaled box (#705)
1 parent e2de468 commit c99d96a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/index.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,19 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
383383
borderBottom
384384
: 0
385385

386+
const scaleX =
387+
'offsetWidth' in frame
388+
? (frame as HTMLElement).offsetWidth === 0
389+
? 0
390+
: width / (frame as HTMLElement).offsetWidth
391+
: 0
392+
const scaleY =
393+
'offsetHeight' in frame
394+
? (frame as HTMLElement).offsetHeight === 0
395+
? 0
396+
: height / (frame as HTMLElement).offsetHeight
397+
: 0
398+
386399
if (scrollingElement === frame) {
387400
// Handle viewport logic (document.documentElement or document.body)
388401

@@ -478,15 +491,15 @@ export default (target: Element, options: Options): CustomScrollAction[] => {
478491
blockScroll = Math.max(
479492
0,
480493
Math.min(
481-
scrollTop + blockScroll,
482-
frame.scrollHeight - height + scrollbarHeight
494+
scrollTop + blockScroll / scaleY,
495+
frame.scrollHeight - height / scaleY + scrollbarHeight
483496
)
484497
)
485498
inlineScroll = Math.max(
486499
0,
487500
Math.min(
488-
scrollLeft + inlineScroll,
489-
frame.scrollWidth - width + scrollbarWidth
501+
scrollLeft + inlineScroll / scaleX,
502+
frame.scrollWidth - width / scaleX + scrollbarWidth
490503
)
491504
)
492505

0 commit comments

Comments
 (0)