ant-design-vue
Version:
An enterprise-class UI design language and Vue-based implementation
56 lines (45 loc) • 1.96 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import { getClientSize } from '../../vc-util/Dom/css';
function fixPoint(key, start, width, clientWidth) {
var startAddWidth = start + width;
var offsetStart = (width - clientWidth) / 2;
if (width > clientWidth) {
if (start > 0) {
return _defineProperty({}, key, offsetStart);
}
if (start < 0 && startAddWidth < clientWidth) {
return _defineProperty({}, key, -offsetStart);
}
} else if (start < 0 || startAddWidth > clientWidth) {
return _defineProperty({}, key, start < 0 ? offsetStart : -offsetStart);
}
return {};
}
/**
* Fix positon x,y point when
*
* Ele width && height < client
* - Back origin
*
* - Ele width | height > clientWidth | clientHeight
* - left | top > 0 -> Back 0
* - left | top + width | height < clientWidth | clientHeight -> Back left | top + width | height === clientWidth | clientHeight
*
* Regardless of other
*/
export default function getFixScaleEleTransPosition(width, height, left, top) {
var _getClientSize = getClientSize(),
clientWidth = _getClientSize.width,
clientHeight = _getClientSize.height;
var fixPos = null;
if (width <= clientWidth && height <= clientHeight) {
fixPos = {
x: 0,
y: 0
};
} else if (width > clientWidth || height > clientHeight) {
fixPos = _extends(_extends({}, fixPoint('x', left, width, clientWidth)), fixPoint('y', top, height, clientHeight));
}
return fixPos;
}