@@ -188,10 +188,10 @@ const getOffsetRectRelativeToCustomParent = (
188188}
189189
190190const getScrollTopValue = ( el : HTMLElement ) =>
191- el === document . body ? Math . max ( document . documentElement . scrollTop , document . body . scrollTop ) : el . scrollTop
191+ el === document . body ? Math . max ( document . documentElement . scrollTop , document . body . scrollTop ) : el . scrollTop || 0
192192
193193const getScrollLeftValue = ( el : HTMLElement ) =>
194- el === document . body ? Math . max ( document . documentElement . scrollLeft , document . body . scrollLeft ) : el . scrollLeft
194+ el === document . body ? Math . max ( document . documentElement . scrollLeft , document . body . scrollLeft ) : el . scrollLeft || 0
195195
196196const getMaxWH = ( body , html ) => {
197197 const height = Math . max ( body . scrollHeight , body . offsetHeight , html . clientHeight , html . scrollHeight , html . offsetHeight )
@@ -620,17 +620,18 @@ export class PopperJS {
620620 placementOpposite = getOppositePlacement ( placement )
621621
622622 let popperOffsets = getPopperClientRect ( data . offsets . popper )
623- // 变量起名不佳。 此处分2种情况: placement是right', 'bottom 或 left,top
624- let a = ~ [ 'right' , 'bottom' ] . indexOf ( placement )
625- let p = Math . floor ( data . offsets . reference [ placement ] )
626- let po = Math . floor ( popperOffsets [ placementOpposite ] )
623+ let isRightOrBottom = [ 'right' , 'bottom' ] . includes ( placement )
624+ // reference元素的对应的位置
625+ let refPosition = Math . floor ( data . offsets . reference [ placement ] )
626+ // 弹出层对应的位置
627+ let popupPosition = Math . floor ( popperOffsets [ placementOpposite ] )
627628
628629 // 如果right, ref.right > pop.left
629630 // bottom, ref.bottom > pop.top
630631 // left, ref.left < pop.left
631632 // top, ref.top < pop.bottom
632633 // 则进行flip
633- if ( ( a && p > po ) || ( ! a && p < po ) ) {
634+ if ( ( isRightOrBottom && refPosition > popupPosition ) || ( ! isRightOrBottom && refPosition < popupPosition ) ) {
634635 data . flipped = true
635636 data . placement = flipOrderArr [ index + 1 ]
636637
0 commit comments