禁止在微信浏览器上下滑动及缩小放大

1. 设置头

    <meta  charset="utf-8" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />

2.css

 <style>
        html, body {
            margin: 0;
            height: 100%;
            width: 100%;
            overflow: hidden;
        }
        .index_body {
            overflow-y: hidden;
            height: 100%;
            position: fixed;
        }
 </style>

3.js   (需要引用jquery)  不想依赖的话自己修改下,。 

<script type="text/javascript">
    $('body').on('touchmove', function (event) {
        event.preventDefault();
    });
    if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){
        $('body').addClass('index_body');
    }else{
        $('body').removeClass('index_body');
    }
</script>
发布了36 篇原创文章 · 获赞 4 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_39342142/article/details/100576058