pc端页面在移动端等比例缩放

pc端页面在移动端等比例缩放


两步:

1.替换head标签内 name="viewport"的 meta标签

<!-- pc端在手机端等比例缩放 -->
<meta name="viewport" content="width=device-width,intial-scale=0,maximum-scale=0,user-scalable=yes,shrink-to-fit=no">

2.屏幕尺寸变化时js操作

window.onresize = function () {
    var winW = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
    if (window.screen.width < 1366) { //小于1366屏幕时做屏幕缩放为768
         $('head').remove('[name="viewport"]')
         $('head').append('')
     } else {
         $('head').remove('[name="viewport"]')
     }
}

参考:https://blog.csdn.net/qq_43378577/article/details/125556805

你可能感兴趣的:(javascript,开发语言,ecmascript,html,前端)