当前位置:   article > 正文

html5中自适应代码,html5 屏幕自适应代码

自适应代码写法

var standardDpi,dpi,w,scale;

w = window.screen.width;

if(w>0){

if(w < 320){

standardDpi = 120;

}else if(w < 480){

standardDpi = 160;

}else if(w < 640){

standardDpi = 240;

}else if(w < 960){

standardDpi = 320;

}else if(w < 1280){

standardDpi = 480;

}else{

standardDpi = 640;

}

}

dpi = 640*standardDpi/w;

dpi = Math.floor(dpi);

scale = 640/w;

document.querySelector("meta[name=viewport]").setAttribute('content','width=640,initial-scale=1.0, maximum-scale=3.0, minimum-scale=1.0,target-densitydpi='+dpi+', user-scalable=0');

if ("-ms-user-select" in document.documentElement.style && navigator.userAgent.match(/IEMobile\/10\.0/))

{

var msViewportStyle = document.createElement("style");

msViewportStyle.appendChild(

document.createTextNode("@-ms-viewport{width:auto!important}")

);

document.getElementsByTagName("head")[0].appendChild(msViewportStyle);

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/247599
推荐阅读
相关标签
  

闽ICP备14008679号