jquery下滑到一定高度后,顶部固定

忘了从哪里复制的代码稍加修改了,留下来以后用

 $(document).ready(function(e) {
        t = $('.fixed').offset().top;//获取匹配元素在当前视口的相对偏移 .offset().top:获得位移高度
        mh = $('body').height();
        fh = $('.fixed').height();
        $(window).scroll(function(e){
            s = $(document).scrollTop();
            if(s > t - 10){
                $('.fixed').css('position','fixed');
                $('.qubie_detail').first().css("margin-top",fh);
                if(s + fh > mh){
                    $('.fixed').css('top',mh-s-fh+'px');
                }
            }else{
                $('.fixed').css('position','');
                $('.qubie_detail').first().css("margin-top",'0');
            }
        })
})
原文地址:https://www.cnblogs.com/ting-0424/p/13253806.html