jquery侧边吸顶效果,不遮挡底部,到底部自动向上跟随

曹え 5811 发布于:2022-08-01 15:36:57

startop = $('.m-outline').offset().top // 开始吸顶的位置
	bottom2 = $('.m-moreservices').offset().top // 底部位置
	height2 = $('.g-fixed').height() + 20 // 侧边高度
	yin2 = bottom2-height2 // 底部出现的位置
	
	

    $(document).on('scroll', function() {
        var scrollH = $(this).scrollTop();
        var ww = $("body").width();
        var w1 = $(".wp").width();
        var w2 = (ww - w1) / 2;
        if (scrollH > startop) {
            $('.g-fixed').addClass('fixed');
			
			s = scrollH + height2
			if(s>bottom2){
				console.log(scrollH,yin2 - scrollH)
				px = yin2 - scrollH 
			}else{
				px = 0
			}
			
            $('.g-fixed').css({
                "top": px + "px",
                "right": w2
            });
			
        } else {
            $('.g-fixed').removeClass('fixed');
        }
    })


觉得有用请点个赞吧!
0 1104