移动端适配的集中方法

 
  
//pc和移动端同时使用
( function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
if(clientWidth>= 640){
docEl.style.fontSize = '50px';
} else{
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
}
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener( 'DOMContentLoaded', recalc, false);
})( document, window);
//移动端的适配
( function(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener( 'DOMContentLoaded', recalc, false);
})( document, window);
//移动端的适配
function resize(originSize,type){
var type=type|| "x";
var widths= document.documentElement.clientWidth;
var heights= document.documentElement.clientHeight;
if(type== "x"){
var scale=widths/originSize* 100;
} else if(type== "y"){
var scale=heights/originSize* 100;
}
document.getElementsByTagName( "html")[ 0].style.fontSize=scale+ "px";
}
resize( 750, "x");

你可能感兴趣的:(移动端适配的集中方法)