简体   繁体   English

如何检测页面底部并阻止侧面导航增加边距

[英]How to detect bottom of page and stop side nav from adding margin

When my sidebar hits the bottom of the page when a user is scrolling, it continues to add white space to the bottom of the page. 当用户滚动时,当我的侧边栏到达页面底部时,它将继续在页面底部添加空白。 Cannot figure out how to stop this from happening once the user hits the bottom of the page. 一旦用户点击页面底部,就无法确定如何阻止这种情况的发生。

$(function() {
        var offset = $("#sidebar").offset();
        var topPadding = 300;

        $(window).scroll(function() {
            if ($(window).scrollTop() > offset.top) {
                $("#sidebar").stop().animate({
                    marginTop: $(window).scrollTop() - offset.top + topPadding
                });
            } 

            else {
                $("#sidebar").stop().animate({
                    marginTop: 80
                });
            };  

        });
    });

I'm guessing that #sidebar is taller than the viewport, and is causing the entire body to grow, as it extends past the bottom of the body when you scroll all the way down. 我猜想#sidebar比视口高,并且会导致整个身体增长,因为当您向下滚动时,它会延伸超过身体底部。

I would look into limiting the height of the sidebar programatically. 我将研究以编程方式限制边栏的高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM