在页面中的导航栏,滑动到顶部后置顶

//搜索栏置顶
        $.fn.fixedDiv = function(actCls){
            var that = $(this),
            offsetTop = that.offset().top,
            scrollTop;
            function fix(){
                scrollTop = $(document).scrollTop();   
                if (scrollTop > offsetTop ) {
                    that.addClass(actCls);
                } else {
                    that.removeClass(actCls);
                }
            }
            fix();
            $(window).scroll(fix);
        }
        $('.weui_search_bar').fixedDiv('fix-div');
<div class="weui_search_bar">
            <form class="weui_search_outer">
                <div class="weui_search_inner">
                    <i class="weui_icon_search">i>
                    <input type="search" class="weui_search_input username_search" id="weui_search_input" placeholder="关键字" required="">
                    <a href="javascript:" class="weui_icon_clear">a>
                div>
                <label for="weui_search_input" class="weui_search_text">
                    <i class="weui_icon_search">i>
                    <span>关键字span>
                label>
            form>
            <a href="javascript:" class="weui_search_cancel">取消a>
        div>

// 还是使用了weui

.fix-div{ 
        margin: 0 auto;
        position: fixed;
        width: 100%; 
        top: 0;       /*只有一个导航所以top值固定*/
        left: 0; 
        right: 0;
        z-index: 99999;
    }

你可能感兴趣的:(html学习)