通过改变viewport 实现网站自适应
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过改变viewport 实现网站自适应相关的知识,希望对你有一定的参考价值。
var phoneWidth = parseInt(window.screen.width); var phoneScale = phoneWidth/640; var userAgent = navigator.userAgent; var index = userAgent.indexOf("android"); if(index >= 0){ var androidVersion = parseFloat(userAgent.slice(index+8)); if(androidVersion>2.3){ $("head").eq(0).append("<meta name=‘viewport‘ content=‘width=640, initial-scale = "+phoneScale+", minimum-scale = "+phoneScale+", maximum-scale = "+phoneScale+",user-scalable=no, target-densitydpi=device-dpi‘>"); }else{ $("head").eq(0).append("<meta name=‘viewport‘ content=‘width=640, target-densitydpi=device-dpi‘>"); } }else{ $("head").eq(0).append("<meta name=‘viewport‘ content=‘width=640, initial-scale = "+phoneScale+", minimum-scale = "+phoneScale+", maximum-scale = "+phoneScale+",user-scalable=no, target-densitydpi=device-dpi‘>"); }
以上是关于通过改变viewport 实现网站自适应的主要内容,如果未能解决你的问题,请参考以下文章