mmenu-js
Version:
The best javascript plugin for app look-alike on- and off-canvas menus with sliding submenus for your website and webapp.
16 lines (15 loc) • 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;
};