移动端粘性布局,低版本ios 7.1.2 touchmove触发频率太低怎么办?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    <title>layout</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .page-header {
            height: 48px;
            background: #009C42;

        }

        .page-content {
            overflow-y: scroll;
            -webkit-overflow-scrolling: touch;
        }

        .page-footer {
            height: 55px;
            background: #1f5350;
        }

        .a1 {
            height: 300px;
            background: #eee;
        }

        .a2 {
            height: 600px;
            background: #999;
        }

        .a3 {
            height: 300px;
            background: #eee;
        }

        .nav {
            height: 50px;
            box-sizing: border-box;
            background: #f50;
            width: 100%;
            top: 48px;
        }

    </style>
    <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<div id="app">
    <header class="page-header"></header>
    <article class="page-content">
        <div class="a1"></div>
        <div class="a2">
            <nav class="nav"></nav>
        </div>
        <div class="a3"></div>
    </article>
    <footer class="page-footer"></footer>
</div>
<script>
    $(function () {
        $('.page-content').height($(window).height() - $('.page-header').outerHeight() - $('.page-footer').outerHeight());
        $('.page-content').on('scroll', fixedNav);
        $('.page-content').on('touchmove', fixedNav);
    });
    function fixedNav() {
        var offsetTop = $('.a2').offset().top;
        if (offsetTop <= $('.page-header').outerHeight()) {
            $('.nav').css({position: 'fixed'});
        } else {
            $('.nav').css({position: 'static'});
        }
    }
</script>
</body>
</html>
阅读 2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题