import {iPopupRefreshBuildParams} from "../utils/popup.utils"; import {handleDirection} from "../utils/handleDirection"; import {ClientZoom} from "../../../utils/ClientZoom"; /** * 应用位置变化 * transformLocation为true的时候,使用transform来定位 * transformLocation为false的时候,使用fixed定位(适合在滚动期间频繁更新定位的情况下使用) * @author 韦胜健 * @date 2023/5/16 16:15 */ export function applyPosition( { top, left, buildParams: { direction, align, refs, rects, transformLocation, }, }: { top: number, left: number, buildParams: iPopupRefreshBuildParams, } ) { const { clientHeight, clientWidth } = ClientZoom.getClientSize(); if (transformLocation) { refs.popupEl.style.top = '0'; refs.popupEl.style.left = '0'; refs.popupEl.style.transform = `translate3d(${left}px,${top}px,0)`; } else { const applyTopStyle = () => refs.popupEl.style.top = `${top}px`; const applyBottomStyle = () => refs.popupEl.style.bottom = `${clientHeight - top - rects.popupEl.height}px`; const applyLeftStyle = () => refs.popupEl.style.left = `${left}px`; const applyRightStyle = () => refs.popupEl.style.right = `${clientWidth - left - rects.popupEl.width}px`; handleDirection(direction, { top: () => { applyBottomStyle(); align !== 'end' ? applyLeftStyle() : applyRightStyle(); }, bottom: () => { applyTopStyle(); align !== 'end' ? applyLeftStyle() : applyRightStyle(); }, left: () => { applyRightStyle(); align !== 'end' ? applyTopStyle() : applyBottomStyle(); }, right: () => { applyLeftStyle(); align !== 'end' ? applyTopStyle() : applyBottomStyle(); }, }); } }