iep-ui
Version:
An enterprise-class UI design language and Vue-based implementation
39 lines (34 loc) • 1.22 kB
JavaScript
import _extends from 'babel-runtime/helpers/extends';
import _defineProperty from 'babel-runtime/helpers/defineProperty';
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);
} else {
return {};
}
}
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({}, fixPoint('x', left, width, clientWidth), fixPoint('y', top, height, clientHeight));
}
return fixPos;
}