File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,13 @@ function position(options: IOptions): PositionData {
9898
9999 parent = parent . parentElement ;
100100 }
101+
102+ // Finally, adjust for window scroll position
103+ const doc = document . documentElement ;
104+ _anchorRect . y +=
105+ ( window . scrollY || doc . scrollTop ) - ( doc . clientTop || 0 ) ;
106+ _anchorRect . x +=
107+ ( window . scrollX || doc . scrollLeft ) - ( doc . clientLeft || 0 ) ;
101108 }
102109
103110 return {
Original file line number Diff line number Diff line change @@ -66,3 +66,38 @@ describe('HoverPosition (collisions ignored)', () => {
6666 } ) ;
6767 } ) ;
6868} ) ;
69+
70+ test ( 'Window scroll adjusts output' , ( ) => {
71+ window . scrollX = 50 ;
72+ window . scrollY = 50 ;
73+
74+ const tP = 'top left' ,
75+ myA = 'top center' ,
76+ atA = 'bottom center' ;
77+
78+ helper . setupTest ( tP ) ;
79+
80+ const pData = position ( {
81+ ...{ debug : true } ,
82+ ...{
83+ my : myA ,
84+ at : atA ,
85+ target : document . querySelector < HTMLDivElement > (
86+ '.target' ,
87+ ) ! ,
88+ anchor : document . querySelector < HTMLElement > ( '.anchor' ) ! ,
89+ collision : CollisionHandler . ignore ,
90+ } ,
91+ } ) as allData ;
92+
93+ expect ( {
94+ left : parseInt ( pData . left , 10 ) ,
95+ top : parseInt ( pData . top , 10 ) ,
96+ } ) . toStrictEqual ( {
97+ left : helper . getLeft ( tP , myA , atA ) + 50 ,
98+ top : helper . getTop ( tP , myA , atA ) + 50 ,
99+ } ) ;
100+
101+ window . scrollX = 50 ;
102+ window . scrollY = 50 ;
103+ } ) ;
You can’t perform that action at this time.
0 commit comments