UNPKG

@txdfe/at

Version:

一个设计体系组件库

55 lines (53 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPosRegion = exports.Region = void 0; var Region = exports.Region = { LeftTop: 'LeftTop', Top: 'Top', RightTop: 'RightTop', LeftBottom: 'LeftBottom', Bottom: 'Bottom', RightBottom: 'RightBottom' }; var RegionMap = [[Region.LeftTop, Region.Top, Region.RightTop], [Region.LeftBottom, Region.Bottom, Region.RightBottom]]; var getRelativePos = function getRelativePos(absPos) { var _document$documentEle = document.documentElement, scrollLeft = _document$documentEle.scrollLeft, scrollTop = _document$documentEle.scrollTop; return { x: absPos.x - scrollLeft, y: absPos.y - scrollTop }; }; /** * 获取坐标所在区域 * @param {object} absPos * @param {number} absPos.x * @param {number} absPos.y * @returns {string} Region */ var getPosRegion = exports.getPosRegion = function getPosRegion(absPos) { var _document$body = document.body, clientWidth = _document$body.clientWidth, clientHeight = _document$body.clientHeight; var pos = getRelativePos(absPos); var rows = RegionMap.length; var cols = RegionMap[0].length; var uw = clientWidth / cols; var uh = clientHeight / rows; var rowIdx = 0; var colIdx = 0; for (var i = 0; i < cols; i++) { if (pos.x >= uw * i) { colIdx = i; } } for (var j = 0; j < rows; j++) { if (pos.y >= uh * j) { rowIdx = j; } } return RegionMap[rowIdx][colIdx]; };