解決 scroll() position:fixed 抖動、導航菜單固定頭部(底部)跟隨屏幕滾動


 

一、導航欄或者頁腳正常情況下固定在頁面的相應位置,當頁面滾動后,導航欄或者頁腳固定在頁面的頂部或者底部的情景

  一般就是將該塊的代碼樣式的position設置為fixed.固定在頂部的話,將top設置為0,或者某一個固定值(例如:200px)

  固定在底部的話就將bottom設置為0.或者固定值。

  實際情況下,當導航欄滑動的時候,在該模塊的位置可能會出現抖動情況。

二、解決抖動

  在將其position:fixed的同事設置內部元素position:absolute;

  

  

1 <div id="footer" style="line-height: 35px;"><!-- class="row" -->
2             <div class="col-md-12 text-right" style="position:absolute;bottom: 8px;right:20px;">
3                 <div class="btn-group" role="group">
4                 </div>
5             </div>
6 </div>
View Code

 

$(window).scroll(
        function () {
            var bottom_height = $(document).height() - $(window).scrollTop() - $(window).height(),
                footer = $("#footer");
            if (bottom_height < 54) {
                //console.log("b===" + bottom_height);
                footer.removeClass("sub_button");
            } else {
                footer.addClass("sub_button");
                footer.find(".col-md-12").css("bottom", "3px");
        }
    });

 

--------------2016-7-11 16--

    source:【1】幾種解決position:fixed抖動的方法


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM