滚动浮动导航,iscroll结构滚动固定元素

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no,email=no" />
        <title>会员详情</title>
        <link href="css/mui.min.css" rel="stylesheet" />
        <style>
            .user-tab-hd{ padding: 9px 0; text-align: center; background: #fbfbfb; width: 100%; margin: 0;}
            .user-tab-hd li{float: left; width: 50%;}
            .user-tab-hd li span{height: 27px; line-height: 27px; width: 103px; text-align: center; border: 1px solid transparent; color: #8b8c8e; border-radius: 27px;}
            .user-tab-hd li.active span{ color: #ff844e; border-color: #e4e4e4;background: #fff;}
            .fixed{position:fixed; top:44px; left:0; z-index:8;}
            .hidden{ display: none !important;}
        </style>
    </head>

    <body>
        <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">test</h1>
        </header>
        <ul class="user-tab-hd fixed hidden" id="fixedNav">
            <li class="active"><span>导航1</span></li>
            <li><span>导航2</span></li>
        </ul>
        <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
            <div class="mui-scroll">
                <div style="height: 200px; background: #0B0C0E;"></div>
                <ul class="user-tab-hd mui-clearfix" id="userTab">
                    <li class="active" data-li="1"><span>导航1</span></li>
                    <li data-li="2"><span>导航2</span></li>
                </ul>
                <div style="height: 400px; background: #0062CC;"></div>
                <div style="height: 400px; background: #25B716;"></div>
            </div>
        </div>

        <script src="js/mui.min.js"></script>
        <script>
            mui.init({
                pullRefresh: {
                    container: '#pullrefresh',
                    deceleration: 0.0006,
                    up: {
                        contentrefresh : "正在加载...",
                        contentnomore: '已加载完全部',
                        callback: loadPage 
                    }
                }
            });

            function loadPage(){

            }

            mui.plusReady(function() {
            });
            // 滚动固定

            var himall={
                removeClass:function(el,name) {
                    if(!el)
                        return;
                    if(el.className.indexOf(name)>=0)
                        el.className=el.className.replace(name,'');
                },
                hasClass:function(el,name) {
                    return (el.className.indexOf(name)>=0);
                }
            };

            var headH = document.querySelector('header').offsetHeight,
                tab = document.getElementById('userTab'),
                fixed = document.getElementById('fixedNav');

            window.addEventListener('scroll', function(e) {
                if(himall.hasClass(fixed, 'hidden')) {
                    if(tab.getBoundingClientRect().top <= headH) {
                        himall.removeClass(fixed, ' hidden');
                    }
                } else if(!himall.hasClass(fixed, 'hidden')){
                    if(tab.getBoundingClientRect().top >= headH){
                        fixed.className += ' hidden';
                    }
                }
            });

        </script>


    </body>
</html>

测试后发现多了一个导航,没能隐藏掉的原因,然后把mui.plusReady(function() {
});加上就可以了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值