滚动条超过一定距离, 导航栏悬浮在最上方

window.onload = function(){
    var tabTop = $("#tab_demo .tabBar").offset().top;
    $(".Hui-article").scroll(function(){
        var currentTop = $(this).scrollTop()+94;
        console.log(currentTop+":"+tabTop);
        if(currentTop >= tabTop){
            var topVal = currentTop - tabTop;
            $("#tab_demo .tabBar").css({
                "position":"relative",
                "top":topVal+"px",
                "left":"0",
                "z-index":"11111",
                "width":"100%",
                "background":"#fff"
            });
        }else{
            $("#tab_demo .tabBar").css({
                "position":"static"
            });
        }
    });
}

  

实现滚动条超过一定距离, 导航栏悬浮在最上方的功能。

posted @ 2017-12-06 11:38  xc_flying  阅读(1659)  评论(0编辑  收藏  举报