@@ -188,10 +188,10 @@ const getOffsetRectRelativeToCustomParent = (
188
188
}
189
189
190
190
const 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
192
192
193
193
const 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
195
195
196
196
const getMaxWH = ( body , html ) => {
197
197
const height = Math . max ( body . scrollHeight , body . offsetHeight , html . clientHeight , html . scrollHeight , html . offsetHeight )
@@ -620,17 +620,18 @@ export class PopperJS {
620
620
placementOpposite = getOppositePlacement ( placement )
621
621
622
622
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 ] )
627
628
628
629
// 如果right, ref.right > pop.left
629
630
// bottom, ref.bottom > pop.top
630
631
// left, ref.left < pop.left
631
632
// top, ref.top < pop.bottom
632
633
// 则进行flip
633
- if ( ( a && p > po ) || ( ! a && p < po ) ) {
634
+ if ( ( isRightOrBottom && refPosition > popupPosition ) || ( ! isRightOrBottom && refPosition < popupPosition ) ) {
634
635
data . flipped = true
635
636
data . placement = flipOrderArr [ index + 1 ]
636
637
0 commit comments