让网页视口适应手机端 简单的JS实现

2017-09-26T16:46:00

自动在页面插入meta 标签 并设置视口

(function(){
    var w = window.screen.width; //屏幕宽度
    var targetW = 320;
    var scale = w/targetW; //当前尺寸/目标尺寸  缩放比例
    var meta = document.createElement("meta");
    meta.name = "viewport";
    meta.content = "user-scalable=no,initial-scale="+scale+",minimum-scale="+scale+",maximum-scale="+scale+""
    document.head.appendChild(meta); //添加标签
})();
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »