functionunitConversion () { /** * 获取DPI * @returns {Array} */ this.getDPI = function () { var arrDPI = newArray(); if (window.screen.deviceXDPI != undefined) { arrDPI[0] = window.screen.deviceXDPI; arrDPI[1] = window.screen.deviceYDPI; } else { var tmpNode = document.createElement("DIV"); tmpNode.style.cssText = "width:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility:hidden"; document.body.appendChild(tmpNode); arrDPI[0] = parseInt(tmpNode.offsetWidth); arrDPI[1] = parseInt(tmpNode.offsetHeight); tmpNode.parentNode.removeChild(tmpNode); } return arrDPI; }; /** * px转换为mm * @paramvalue * @returns {number} */ this.px2mm = function (value) { var inch = value / this.getDPI()[0]; var c_value = inch * 25.4; return c_value; };
/** * mm转换为px * @paramvalue * @returns {number} */ this.mm2px = function (value) { var inch = value / 25.4; var c_value = inch * this.conversion_getDPI()[0]; return c_value; } }