$inital-rem-size: 100px !default;
$design-width: 375px !default;
html {
font-size: $inital-rem-size / $design-width * 320px;
}
@each $width in (320px, 360px, 400px, 414px, 480px, 500px, 650px) {
@media only screen and (min-width: #{$width}) {
html {
font-size: $inital-rem-size / $design-width * $width;
}
}
}
@function px2rem($px) {
@if unitless($px) {
$px: $px * 1px;
}
@return $px / $inital-rem-size * 1rem;
}
!(function(win, doc) {
var dui = window.dui || (window.dui = {}),
timer = null,
firstCalled = true,
defaults = {
designWidth: 375,
initRem: 100,
maxWinWidth: 640,
minWinWidth: 320,
},
evts = 'onorientationchange' in win ? ['orientationchange', 'resize'] : ['resize'];
if (dui.flexrem !== undefined) {
return console.error('flexrem.js shouldn\'t be called twice!!')
}
dui.flexrem = function(opts) {
if(!firstCalled) console.error('flexrem() can only be called once!');
firstCalled =false
var options = Object.assign({}, defaults, opts)
for (var i = 0; i < evts.length; i++) {
win.addEventListener(evts[i], function() {
clearTimeout(timer);
timer = setTimeout(setFontSize, 300);
}, false);
}
win.addEventListener("pageshow", function(e) {
if (e.persisted) {
clearTimeout(timer);
timer = setTimeout(setFontSize, 300);
}
}, false);
setFontSize();
function setFontSize() {
var winWidth = window.innerWidth || window.clientWidth;
winWidth = Math.min(winWidth, options.maxWinWidth)
winWidth = Math.max(winWidth, options.minWinWidth)
var size = (winWidth / options.designWidth) * options.initRem;
doc.documentElement.style.fontSize = size + 'px';
}
}
function toType(obj) {
return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}
if (typeof Object.assign != 'function') {
Object.assign = function (target, varArgs) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) {
for (var nextKey in nextSource) {
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}
}(window, document));