UNPKG

zhu-jiang-yi-yuan-bigscreen

Version:

南方医科大学珠江医院大屏端

135 lines (106 loc) 2.63 kB
import { NType } from 'nsn-util'; var BASE_WIDTH = 3840; var MID_WIDTH = 1920; var MIN_WIDTH = 1440; var SMALL_WIDTH = 1024; var BASE_HEIGHT = 2160; var MID_HEIGHT = 1080; var MIN_HEIGHT = 900; var SMALL_HEIGHT = 768; /** * x < 3840; * isHeight = true 时, x < 2160; */ var isBASE = function isBASE(px, isHeight) { if (px) { if (isHeight) { return px >= MID_HEIGHT; } return px >= MID_WIDTH; } return false; }; /** * 1920<= x < 3840; * isHeight = true 时, 1080<= x < 2160 */ var isBIG = function isBIG(px, isHeight) { if (px) { if (isHeight) { return px >= MID_HEIGHT && px < BASE_HEIGHT; } return px >= MID_WIDTH && px < BASE_WIDTH; } return false; }; /** * 1440<= x < 1920; * isHeight = true 时, 900<= x < 1080 */ var isMID = function isMID(px, isHeight) { if (px) { if (isHeight) { return px >= MIN_HEIGHT && px < MID_HEIGHT; } return px >= MIN_WIDTH && px < MID_WIDTH; } return false; }; /** * 1024<= x <1440; * isHeight = true 时, 768<= x <900 */ var isMIN = function isMIN(px, isHeight) { if (px) { if (isHeight) { return px >= SMALL_HEIGHT && px < MIN_HEIGHT; } return px >= SMALL_WIDTH && px <= MIN_WIDTH; } return false; }; /** * x < 1024; * isHeight = true 时, x < 768 */ var isSMALL = function isSMALL(px, isHeight) { if (px) { if (isHeight) { return px < SMALL_HEIGHT; } return px < SMALL_WIDTH; } return false; }; var getCalcNumH = function getCalcNumH(px, docPx) { return getCalcNum(px, docPx, true); }; var getCalcNumW = function getCalcNumW(px, docPx) { return getCalcNum(px, docPx, false); }; var getCalcNum = function getCalcNum(px, docPx, isHeight) { var currentPx = docPx || 0; if (!docPx) { if (isHeight) { currentPx = document.documentElement.offsetHeight; } else { currentPx = document.documentElement.offsetWidth; } } if (isHeight) { return currentPx * px / MIN_HEIGHT; } return currentPx * px / MIN_WIDTH; }; /** * 将数值转换为比例 *vh 和 *vw * @param px 以 BASE_HEIGHT/BASE_WIDTH 为基准的数值 * @param isHeight 是否是高度数值 */ var getCalcPx = function getCalcPx(px, isHeight) { if (px && !NType.isString(px)) { return "calc(".concat(px, "/").concat(isHeight ? BASE_HEIGHT : BASE_WIDTH, " * ").concat(isHeight ? '100vh' : '100vw'); } return px; }; export { isBASE, isBIG, isMID, isMIN, isSMALL, getCalcPx, getCalcNumH, getCalcNumW, BASE_HEIGHT, BASE_WIDTH, MIN_WIDTH, MID_WIDTH, MID_HEIGHT, MIN_HEIGHT, SMALL_WIDTH, SMALL_HEIGHT };