Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

可自定义的最大宽度,以便适应更宽的屏幕。 #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/flexible.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var docEl = doc.documentElement;
var metaEl = doc.querySelector('meta[name="viewport"]');
var flexibleEl = doc.querySelector('meta[name="flexible"]');
var maxWidthEl = doc.querySelector('meta[name="max-width"]');
var maxWidth = 540;
var dpr = 0;
var scale = 0;
var tid;
Expand Down Expand Up @@ -31,6 +33,13 @@
}
}

if (maxWidthEl) {
var maxWidthContent = maxWidthEl.getAttribute('content');
if (maxWidthContent) {
maxWidth = parseInt(maxWidthContent);
}
}

if (!dpr && !scale) {
var isAndroid = win.navigator.appVersion.match(/android/gi);
var isIPhone = win.navigator.appVersion.match(/iphone/gi);
Expand Down Expand Up @@ -67,8 +76,8 @@

function refreshRem(){
var width = docEl.getBoundingClientRect().width;
if (width / dpr > 540) {
width = 540 * dpr;
if (width / dpr > maxWidth) {
width = maxWidth * dpr;
}
var rem = width / 10;
docEl.style.fontSize = rem + 'px';
Expand Down Expand Up @@ -114,4 +123,4 @@
return val;
}

})(window, window['lib'] || (window['lib'] = {}));
})(window, window['lib'] || (window['lib'] = {}));