2022-11-18 21:38:41 +01:00

16 lines
553 B
JavaScript

/**
* Calculate a distance from a percentage.
* @param {string|number} position The percentage (e.g. "75%").
* @param {number} size The available width or height in pixels.
* @return {number} The calculated distance.
*/
export var percentage2number = function (position, size) {
if (typeof position == 'string') {
if (position.slice(-1) == '%') {
position = parseInt(position.slice(0, -1), 10);
position = size * (position / 100);
}
}
return position;
};