@@ -15,7 +15,14 @@ export const getNewDirectionLocation = ({
15
15
arrowLocation,
16
16
offsetSpacing,
17
17
} ) => {
18
- const { left : cLeft , right : cRight , top : cTop , bottom : cBottom } = rootOffset ;
18
+ const {
19
+ left : cLeft ,
20
+ right : cRight ,
21
+ top : cTop ,
22
+ bottom : cBottom ,
23
+ width : cWidth ,
24
+ height : cHeight ,
25
+ } = rootOffset ;
19
26
const { width, height } = tipOffset ;
20
27
const pgegWidth =
21
28
document . documentElement . clientWidth || document . body . clientWidth ;
@@ -54,15 +61,17 @@ export const getNewDirectionLocation = ({
54
61
const isCenter = arrowLocation === 'center' ;
55
62
// 箭头在中间的情况,是否超过边界
56
63
if ( isCenter && ( isDirectionTop || isDirectionBottom ) ) {
57
- if ( cLeft + width > pgegWidth ) {
64
+ // cLeft + (cWidth - width) / 2 代表浮层最左侧的坐标
65
+ if ( cLeft + ( cWidth - width ) / 2 + width > pgegWidth ) {
58
66
newArrowLocation = directionCssMap . left ;
59
- } else if ( cRight - width < 0 ) {
67
+ } else if ( cLeft + ( cWidth - width ) / 2 < 0 ) {
60
68
newArrowLocation = directionCssMap . right ;
61
69
}
62
70
} else if ( isCenter && ( isDirectionLeft || isDirectionRight ) ) {
63
- if ( cTop + height > pgegHeight ) {
71
+ // cTop + (cHeight - height) / 2 代表浮层最上侧的坐标
72
+ if ( cTop + ( cHeight - height ) / 2 + cHeight > pgegHeight ) {
64
73
newArrowLocation = directionCssMap . top ;
65
- } else if ( cBottom - height < 0 ) {
74
+ } else if ( cTop + ( cHeight - height ) / 2 < 0 ) {
66
75
newArrowLocation = directionCssMap . bottom ;
67
76
}
68
77
}
0 commit comments