Skip to content

Commit

Permalink
手动实现flexiable适配
Browse files Browse the repository at this point in the history
  • Loading branch information
YSMJ1994 committed Dec 12, 2019
1 parent d13f1f6 commit 5ba742a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
40 changes: 40 additions & 0 deletions public/js/flexiable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(function(global, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
define(factory());
} else if (typeof define === 'function' && define.cmd) {
define(function(require, exports, module) {
module.exports = factory();
});
} else {
global.flexiable = factory();
}
})(this, function() {
function isMobile() {
return /(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent);
}
function execute(rem = 16, designWidth = document.documentElement.clientWidth) {
const dpr = window.devicePixelRatio || 1;
const clientWidth = document.documentElement.clientWidth;
const width = clientWidth * dpr;
const scale = 1 / dpr;
const remCalc = (rem * width) / designWidth;
let viewport = document.querySelector('meta[name="viewport"]');
if (!viewport) {
viewport = document.createElement('meta');
viewport.setAttribute('name', 'viewport');
document.head.insertAdjacentElement('afterbegin', viewport);
}
viewport.setAttribute(
'content',
`width=${width}, user-scalable=no, initial-scale=${scale}, maximum-scale=${scale}, minimum-scale=${scale}`
);
document.head.insertAdjacentHTML('beforeend', `<style>html { font-size: ${remCalc}px!important; }</style>`);
}
return function(rem, designWidth) {
if (isMobile()) {
execute(rem, designWidth);
}
};
});
2 changes: 1 addition & 1 deletion src/components/Header/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
.menuIcon {
display: none;
font-size: 20px;
font-size: 1.33rem;
margin: 0 0.35rem 0 1rem;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/Link/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
position: relative;
color: $main-color;
text-transform: capitalize;
line-height: 36px;
line-height: 2.3rem;
display: inline-block;
text-decoration: unset !important;
cursor: pointer;
Expand Down
1 change: 1 addition & 0 deletions src/styles/fix.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ body {

* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}

code {
Expand Down

0 comments on commit 5ba742a

Please sign in to comment.