Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

移动端粘性布局,低版本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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...