/*REM單位換算方法 iphone6適配*/ function resizeRoot(){ var Dpr = 1, uAgent = window.navigator.userAgent; var isIOS = uAgent.match(/iphone/i); var wWidth = (screen.width > 0) ? (window.innerWidth >= screen.width || window.innerWidth == 0) ? screen.width : window.innerWidth : window.innerWidth, wDpr, wFsize; if (window.devicePixelRatio) { wDpr = window.devicePixelRatio; } else { wDpr = isIOS ? wWidth > 818 ? 3 : wWidth > 480 ? 2 : 1 : 1; } if(isIOS) wWidth = screen.width; wFsize = wWidth > 1080 ? 144 : wWidth / 7.5; window.screenWidth_ = wWidth; document.getElementsByTagName('html')[0].dataset.dpr = wDpr; document.getElementsByTagName('html')[0].style.fontSize = wFsize + 'px'; } //判斷安卓手機瀏覽器低版本的用ready方法執行 function appsion(){ uAgent = window.navigator.userAgent; var isIOS = uAgent.match(/iphone/i); if(navigator.appVersion.substring(navigator.appVersion.length-6)<537 && !isIOS){ document.ready=function(){ resizeRoot(); } }else{ resizeRoot(); } } appsion(); //rem配置方法執行
計算APP高度html
var winWidth = 0; var winHeight = 0; function findDimensions() //函數:獲取尺寸 { //獲取窗口寬度 if (window.innerWidth) winWidth = window.innerWidth; else if ((document.body) && (document.body.clientWidth)) winWidth = document.body.clientWidth; //獲取窗口高度 if (window.innerHeight) winHeight = window.innerHeight; else if ((document.body) && (document.body.clientHeight)) winHeight = document.body.clientHeight; //經過深刻Document內部對body進行檢測,獲取窗口大小 if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) { winHeight = document.documentElement.clientHeight; winWidth = document.documentElement.clientWidth; } //結果輸出至兩個文本框 } findDimensions(); //調用函數,獲取數值 window.onresize=findDimensions; function loadAddButton(id){ // window.onload=function(){ var d1=document.getElementById(id); var h1=d1.clientHeight+d1.scrollHeight; var h2=d1.offsetHeight+40; var wheight = winHeight; if(h2<wheight){ // alert(wheight); // alert("wheight:"+wheight); // alert("wheight:"+wheight); document.getElementById(id).style.height=wheight+"px"; }else {//alert("h2:"+h2); document.getElementById(id).style.height=h2+"px"; } //} } function loadAddlist(id,height){ findDimensions(); var wheight = winHeight - height; document.getElementById(id).style.height=wheight+"px"; } function bodyheight(){ findDimensions(); var body = document.getElementsByTagName("body")[0]; body.style.height=winHeight+"px"; } function getBodyheight(){ findDimensions(); return winHeight; } jQuery(function(){ bodyheight(); addEvent(window, 'resize', function () { setTimeout(function(){ bodyheight(); },300); }); }); function addEvent(e, n, o){ if(e.addEventListener){ e.addEventListener(n, o,false); } else if(e.attachEvent){ e.attachEvent('on' + n, o); } }
頁面用rem爲單位寫,但注意點:瀏覽器
1.最外面的寬度用百分比,最好不要用remapp
2.input中line-height不要用,若是字被截,那把文字大小縮小iphone
3.高度要用rem函數