@drozdik.m/dimensions-helper
Version:
Simple helper for getting dimensions (basic, padding, border, margin)
95 lines (94 loc) • 3.47 kB
JavaScript
exports.__esModule = true;
var DimensionsHelper = /** @class */ (function () {
//--------------------------------------------------
//----------CONSTRUCTOR-----------------------------
//--------------------------------------------------
/**
* Creates active container for providing
* @param element
*/
function DimensionsHelper(element) {
this.element = element;
this.style = getComputedStyle(element);
}
//--------------------------------------------------
//----------WIDTH/HEIGHT----------------------------
//--------------------------------------------------
/**
* Returns width of the element
* */
DimensionsHelper.prototype.Width = function () {
return parseInt(this.style.width);
};
/**
* Returns height of the element
* */
DimensionsHelper.prototype.Height = function () {
return parseInt(this.style.height);
};
/**
* Sets new width to the element
* @param width New width
*/
DimensionsHelper.prototype.SetWidth = function (width) {
this.element.style.width = width + "px";
};
/**
* Sets new height to the element
* @param height New height
*/
DimensionsHelper.prototype.SetHeight = function (height) {
this.element.style.height = height + "px";
};
//--------------------------------------------------
//----------PADDING---------------------------------
//--------------------------------------------------
/**
* Returns width with padding of the element
* */
DimensionsHelper.prototype.WidthWithPadding = function () {
return this.element.clientWidth;
};
/**
* Returns height with padding of the element
* */
DimensionsHelper.prototype.HeightWithPadding = function () {
return this.element.clientHeight;
};
//--------------------------------------------------
//----------BORDER----------------------------------
//--------------------------------------------------
/**
* Returns width with padding and border of the element
* */
DimensionsHelper.prototype.WidthWithBorder = function () {
return this.element.offsetWidth;
};
/**
* Returns height with padding and border of the element
* */
DimensionsHelper.prototype.HeightWithBorder = function () {
return this.element.offsetHeight;
};
//--------------------------------------------------
//----------MARGIN----------------------------------
//--------------------------------------------------
/**
* Returns width with padding, border and margin of the element
* */
DimensionsHelper.prototype.WidthWithMargin = function () {
var marginLeft = parseInt(this.style.marginLeft);
var marginRight = parseInt(this.style.marginRight);
return this.WidthWithBorder() + marginLeft + marginRight;
};
/**
* Returns height with padding, border and margin of the element
* */
DimensionsHelper.prototype.HeightWithMargin = function () {
var marginTop = parseInt(this.style.marginTop);
var marginBottom = parseInt(this.style.marginBottom);
return this.HeightWithBorder() + marginTop + marginBottom;
};
return DimensionsHelper;
}());
exports.DimensionsHelper = DimensionsHelper;