@ohu-mobile/core
Version:
40 lines (39 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.computeCSSValue = computeCSSValue;
exports.getClientRectByDirection = getClientRectByDirection;
exports.setTransformByDirection = setTransformByDirection;
function computeCSSValue(cssValue) {
var defaultUnit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'px';
var unit = defaultUnit;
var value = 0;
if (typeof cssValue === 'string') {
cssValue.replace(/([0-9]+)([a-zA-Z]+)?/g, function (_, v, u) {
if (v) value = parseInt(v, 10);
if (u) unit = u;
return '';
});
}
return {
unit: unit,
value: value
};
}
function getClientRectByDirection(el, direction) {
var _el$getBoundingClient = el.getBoundingClientRect(),
width = _el$getBoundingClient.width,
height = _el$getBoundingClient.height;
if (direction === 'horizontal') {
return width;
}
return height;
}
function setTransformByDirection(style, direction, offset) {
if (direction === 'horizontal') {
style.transform = "translate3d(".concat(offset, "px, 0, 0)");
} else {
style.transform = "translate3d(0, ".concat(offset, "px, 0)");
}
}