移动端浏览器body的overflow:hidden没有什么作用

2018-03-21  本文已影响0人  大乔是个美少女
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/static/css/reset.css">
    <link rel="stylesheet" href="/static/css/all.css">
    <title>书城首页</title>
    <style type="text/css">
        #root {
            width: 100%;
            height: 100%;
            position: fixed;
        }
        .container-warp {
            height: 100%;
            overflow: hidden;
            position: relative;
        }
        .container-scroll {
            position: absolute;
            top: 45px;
            bottom: 0px;
            left: 0px;
            right: 0px;
            overflow-y: scroll;
        }
    </style>
</head>
<body>
    <div id="root">
        <div class="container-warp">
            <% include include/header.html %>
            <div class="container-scroll">
                <% include include/index-top.html %>
                <% include include/index-hot.html %>
                <% include include/index-recommend.html %>
                <% include include/index-female.html %>
                <% include include/index-male.html %>
                <% include include/index-free.html %>
                <% include include/index-bottom.html %>
            </div>
        </div>
    </div>
    <script src="/static/script/vue.min.js"></script>
    <script src="/static/script/zepto.min.js"></script>
    <script src="/static/script/pages/index.js"></script>
</body>
</html>

三种解决方案

1、body加position:fixed;width:100%;height:100%。

2、给要滚动的元素添加一个父级,设定高度,overflow:auto;

3、html,body{height:100%;overflow:hidden}

建议使用第三种,可以把overflow:hidden作为一个单独的隐藏类,更方便控制。

上一篇 下一篇

猜你喜欢

热点阅读