js导航冻结在顶部滚动一直显示效果,兼容ie6+

作者:Jasmine - 2018年04月17日

js导航冻结在顶部滚动一直显示效果,兼容ie6+.

css:

.floatnv{position:fixed;_position:absolute;top:0px;z-index:999;width:100%; left:0;right:0;margin:auto}

js:

$(function () {
    var oDiv = document.getElementById("menu");
    var H = 0, iE6;
    var Y = oDiv;
    while (Y) {
        H += Y.offsetTop;
        Y = Y.offsetParent;
    }
    ;
    iE6 = window.ActiveXObject && !window.XMLHttpRequest;
    if (!iE6) {
        window.onscroll = function () {
            var s = document.body.scrollTop || document.documentElement.scrollTop;
            if (s > H) {
                oDiv.className = "floatnv";
                if (iE6) {
                    oDiv.style.top = (s - H) + "px";
                }
            } else {
                oDiv.className = "";
            }
        }
    }
});


本文作者: Jasmine

本文链接: https://www.jianbaizhan.com/article/596

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!


 请勿发布不友善或者负能量的内容。审查将对发布广告等违规信息进行处罚!