File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -35,3 +35,27 @@ export const hasOverflowScroll = (element: HTMLElement): boolean => {
3535 let style = element . style ;
3636 return style . overflowY === 'scroll' || style . overflow === 'scroll' || style . overflowY === 'auto' || style . overflow === 'auto' ;
3737}
38+
39+ export const getDistanceToParent = ( child : HTMLElement , parent : HTMLElement ) => {
40+ const offsetParent = child . offsetParent as HTMLElement ;
41+ const childOffsetTop = child . offsetTop ;
42+ // [el] <-- offset parent === parent
43+ // [el] <-- child
44+ if ( offsetParent === null || offsetParent === parent ) {
45+ return childOffsetTop ;
46+ }
47+ else {
48+ // [el] <-- offset parent
49+ // [el] <-- parent
50+ // [el] <-- child
51+ if ( offsetParent . contains ( parent ) ) {
52+ return childOffsetTop - parent . offsetTop ;
53+ }
54+ // [el] <-- parent
55+ // [el] <-- offset parent
56+ // [el] <-- child
57+ else {
58+ return childOffsetTop + getDistanceToParent ( offsetParent , parent ) ;
59+ }
60+ }
61+ }
Original file line number Diff line number Diff line change @@ -36,7 +36,8 @@ import {
3636} from './utilities' ;
3737import {
3838 getElementDistanceToTopOfDocument ,
39- hasOverflowScroll
39+ hasOverflowScroll ,
40+ getDistanceToParent
4041} from './utilities-dom' ;
4142import { VirtualRepeatStrategyLocator } from './virtual-repeat-strategy-locator' ;
4243import { TemplateStrategyLocator } from './template-strategy-locator' ;
@@ -565,7 +566,10 @@ export class VirtualRepeat extends AbstractRepeater {
565566 const topBuffer = this . topBufferEl ;
566567 const scroller = this . scrollContainer ;
567568 const itemHeight = this . itemHeight ;
568- const topBufferDistance = topBuffer . offsetTop - scroller . offsetTop ;
569+ // If offset parent of top buffer is the scroll container
570+ // its actual offsetTop is just the offset top itself
571+ // If not, then the offset top is calculated based on the parent offsetTop as well
572+ const topBufferDistance = getDistanceToParent ( topBuffer , scroller ) ;
569573 const isFixedHeightContainer = this . _fixedHeightContainer ;
570574 /**
571575 * Real scroll top calculated based on current scroll top of scroller and top buffer {height + distance to top}
You can’t perform that action at this time.
0 commit comments