responsive-height-js
Version:
大屏响应式方案插件
2 lines (1 loc) • 3.14 kB
JavaScript
function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(n)}function n(n){var e=t(n);return null!=n&&("object"==e||"function"==e)}var e="object"==("undefined"==typeof global?"undefined":t(global))&&global&&global.Object===Object&&global,o="object"==("undefined"==typeof self?"undefined":t(self))&&self&&self.Object===Object&&self,r=e||o||Function("return this")(),i=function(){return r.Date.now()},u=/\s/;var c=/^\s+/;function f(t){return t?t.slice(0,function(t){for(var n=t.length;n--&&u.test(t.charAt(n)););return n}(t)+1).replace(c,""):t}var l=r.Symbol,a=Object.prototype,v=a.hasOwnProperty,d=a.toString,s=l?l.toStringTag:void 0;var m=Object.prototype.toString;var y=l?l.toStringTag:void 0;function b(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":y&&y in Object(t)?function(t){var n=v.call(t,s),e=t[s];try{t[s]=void 0;var o=!0}catch(t){}var r=d.call(t);return o&&(n?t[s]=e:delete t[s]),r}(t):function(t){return m.call(t)}(t)}function p(n){return"symbol"==t(n)||function(n){return null!=n&&"object"==t(n)}(n)&&"[object Symbol]"==b(n)}var g=/^[-+]0x[0-9a-f]+$/i,S=/^0b[01]+$/i,h=/^0o[0-7]+$/i,j=parseInt;function O(t){if("number"==typeof t)return t;if(p(t))return NaN;if(n(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=n(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=f(t);var o=S.test(t);return o||h.test(t)?j(t.slice(2),o?2:8):g.test(t)?NaN:+t}var T=Math.max,w=Math.min;function E(t,e,o){var r,u,c,f,l,a,v=0,d=!1,s=!1,m=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(n){var e=r,o=u;return r=u=void 0,v=n,f=t.apply(o,e)}function b(t){var n=t-a;return void 0===a||n>=e||n<0||s&&t-v>=c}function p(){var t=i();if(b(t))return g(t);l=setTimeout(p,function(t){var n=e-(t-a);return s?w(n,c-(t-v)):n}(t))}function g(t){return l=void 0,m&&r?y(t):(r=u=void 0,f)}function S(){var t=i(),n=b(t);if(r=arguments,u=this,a=t,n){if(void 0===l)return function(t){return v=t,l=setTimeout(p,e),d?y(t):f}(a);if(s)return clearTimeout(l),l=setTimeout(p,e),y(a)}return void 0===l&&(l=setTimeout(p,e)),f}return e=O(e)||0,n(o)&&(d=!!o.leading,c=(s="maxWait"in o)?T(O(o.maxWait)||0,e):c,m="trailing"in o?!!o.trailing:m),S.cancel=function(){void 0!==l&&clearTimeout(l),v=0,r=a=u=l=void 0},S.flush=function(){return void 0===l?f:g(i())},S}function x(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1080,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:16,e=document.documentElement,o="";function r(){var e=document.documentElement;e&&(e.style.fontSize=e.clientHeight/t*n+"px")}e&&e.style.fontSize&&(o=e.style.fontSize);var i=E(r,300);return{setRootFontSize:r,Start:function(){r(),window.addEventListener("resize",i)},Stop:function(){e&&(e.style.fontSize=o),window.removeEventListener("resize",i)}}}function z(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1080;return document&&document.documentElement?document.documentElement.clientHeight/n*t:t}export{z as setSizeRem,x as useResize};