UNPKG

d-utils

Version:

d-utils

28 lines (27 loc) 2.79 kB
/** * d-utils version: 4.0.3 * by ifmiss */ /** * 设备相关 */ var t=/** @class */function(){function t(){} /** * @description 横竖屏的判断,如果是横屏幕显示,显示dom提示竖屏显示 * @param { String } 提示内容 * @example * DeviceUtils.checkLayoutOrientation() // 横屏时候提示 请旋转屏幕,以达到更好的浏览效果 * @example * DeviceUtils.checkLayoutOrientation('请竖直使用手机') // 横屏时候提示 请竖直使用手机 */return t.checkLayoutOrientation=function(t){if(void 0===t&&(t="请旋转屏幕,以达到更好的浏览效果"),window.hasOwnProperty("orientation")){var n=null; // 0 和 360 的时候是竖屏 e(),window.addEventListener("orientationchange",(function(){e()}))}function e(){var e=window.orientation;if(0===e||360===e)n&&(document.body.removeChild(n),n=null);else{if(n)return;(n=document.createElement("div")).style.cssText="position: fixed;\n top: 0;\n left: 0;\n right:0;\n bottom:0;\n display:flex;\n align-items:center;\n justify-content:center;\n font-size: 20px;\n background:#fff;\n z-index: 19940320;\n padding: 40px;",n.innerText=t,document.body.appendChild(n)}}}, /** * @description 移动端REM的初始化js的方法,默认基于750的设计稿,可以限制最大显示宽度, 超出需要isFullOverMax 判断是否全屏幕显示, 不全屏则是body居中 * @param { number } BaseWidth 基础的设计稿宽度 默认750 * @param { number } MaxWidth 移动端最大的比例宽度点 默认document.body.clientWidth * @param { boolean } isFullOverMax 超出{MaxWidth}最大宽度的时候是否居中显示(body居中的前提是超出设定的宽度以及isFullOverMax=false) 默认false * @example * DeviceUtils.initRem() */ t.initRem=function(t,n,e){void 0===t&&(t=750),void 0===n&&(n=document.body.clientWidth),void 0===e&&(e=!0);var i={},o=n/t;i.Html=document.getElementsByTagName("html")[0],i.intiFontSize=function(){var n=Math.min(document.body.clientWidth,document.body.clientHeight),i=parseFloat((n/t).toFixed(4)),d=i>o?o:i;return e&&(d=i),d},i.updateFontSize=function(){i.Html.setAttribute("style","font-size:"+100*i.intiFontSize()+"px"),!e&&document.body.clientWidth>=n&&document.body.setAttribute("style","margin: 0 auto; width: 7.5rem")},document.addEventListener&&(window.addEventListener("resize",i.updateFontSize,!1),document.addEventListener("DOMContentLoaded",i.updateFontSize,!1))},t}();export default t;