码迷,mamicode.com
首页 > Web开发 > 详细

通过改变viewport 实现网站自适应

时间:2016-01-26 16:35:59      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

     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 实现网站自适应

标签:

原文地址:http://www.cnblogs.com/cainiaoz/p/5160769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!