@@ -361,37 +361,51 @@ export class JigsawFloat extends AbstractJigsawViewBase implements OnDestroy {
361361 private _positionReviser ( pos : PopupPositionValue , popupElement : HTMLElement ) : PopupPositionValue {
362362 const offsetWidth = this . _elementRef . nativeElement . offsetWidth ;
363363 const offsetHeight = this . _elementRef . nativeElement . offsetHeight ;
364+ // 调整上下左右位置
364365 if ( this . jigsawFloatPosition === 'topLeft' || this . jigsawFloatPosition === 'topRight' ||
365366 this . jigsawFloatPosition === 'bottomLeft' || this . jigsawFloatPosition === 'bottomRight' ) {
366- // 调整上下位置
367367 const upDelta = offsetHeight + popupElement . offsetHeight ;
368- if ( document . body . clientHeight <= upDelta ) {
369- // 可视区域比弹出的UI高度还小就不要调整了
370- return pos ;
371- }
372- const totalHeight = window . pageYOffset + document . body . clientHeight ;
373- if ( pos . top < 0 && pos . top + upDelta <= totalHeight ) {
374- // 上位置不够且下方位置足够的时候才做调整
375- pos . top += upDelta ;
376- } else if ( pos . top + popupElement . offsetHeight >= totalHeight && pos . top >= upDelta ) {
377- // 下方位置不够且上方位置足够的时候才做调整
378- pos . top -= upDelta ;
379- }
368+ pos = this . _calPositionY ( pos , upDelta , popupElement ) ;
369+ const leftDelta = popupElement . offsetWidth ;
370+ pos = this . _calPositionX ( pos , leftDelta , popupElement ) ;
380371 } else {
381- // 调整左右位置
372+ const upDelta = popupElement . offsetHeight ;
373+ pos = this . _calPositionY ( pos , upDelta , popupElement ) ;
382374 const leftDelta = popupElement . offsetWidth + offsetWidth ;
383- if ( document . body . clientWidth <= leftDelta ) {
384- // 可视区域比弹出的UI高度还小就不要调整了
385- return pos ;
386- }
387- const totalWidth = window . pageXOffset + document . body . clientWidth ;
388- if ( pos . left < 0 && pos . left + leftDelta <= totalWidth ) {
389- // 左边位置不够且右边位置足够的时候才做调整
390- pos . left += leftDelta ;
391- } else if ( pos . left + popupElement . offsetWidth >= totalWidth && pos . left >= leftDelta ) {
392- // 右边位置不够且左边位置足够的时候才做调整
393- pos . left -= leftDelta ;
394- }
375+ pos = this . _calPositionX ( pos , leftDelta , popupElement ) ;
376+
377+ }
378+ return pos ;
379+ }
380+
381+ private _calPositionX ( pos , leftDelta , popupElement ) {
382+ if ( document . body . clientWidth <= leftDelta ) {
383+ // 可视区域比弹出的UI宽度还小就不要调整了
384+ return pos ;
385+ }
386+ const totalWidth = window . pageXOffset + document . body . clientWidth ;
387+ if ( pos . left < 0 && pos . left + leftDelta + popupElement . offsetWidth <= totalWidth ) {
388+ // 左边位置不够且右边位置足够的时候才做调整
389+ pos . left += leftDelta ;
390+ } else if ( pos . left + popupElement . offsetWidth >= totalWidth && pos . left >= leftDelta ) {
391+ // 右边位置不够且左边位置足够的时候才做调整
392+ pos . left -= leftDelta ;
393+ }
394+ return pos ;
395+ }
396+
397+ private _calPositionY ( pos , upDelta , popupElement ) {
398+ if ( document . body . clientHeight <= upDelta ) {
399+ // 可视区域比弹出的UI高度还小就不要调整了
400+ return pos ;
401+ }
402+ const totalHeight = window . pageYOffset + document . body . clientHeight ;
403+ if ( pos . top < 0 && pos . top + upDelta + popupElement . offsetHeight <= totalHeight ) {
404+ // 上位置不够且下方位置足够的时候才做调整
405+ pos . top += upDelta ;
406+ } else if ( pos . top + popupElement . offsetHeight >= totalHeight && pos . top >= upDelta ) {
407+ // 下方位置不够且上方位置足够的时候才做调整
408+ pos . top -= upDelta ;
395409 }
396410 return pos ;
397411 }
0 commit comments