简体   繁体   English

滚动到底部附近时如何使Div消失

[英]How to make Div disappear when scrolling (this) close to bottom

Basically,I want a div (sidebar) to slide off to the left when the user scrolls to, for example, 50px away from the bottom of the page, the closest thing I found is this piece of code 基本上,我希望当用户滚动到距页面底部50px的距离时,div(侧边栏)向左滑动,我找到的最接近的代码是这段代码

<script>
    $(window).bind('scroll', function() {
     if ($(window).scrollTop() > 100) {
         $('#myDivId').hide();
     }
     else {
         $('#myDivId').show();
     }
});
    </script>

I tried modifying it but to no avail.I already have a transition attribute so all I need is basically to have the div's position become -100px to the left. 我尝试修改它,但无济于事。我已经有一个transition属性,所以我所需要做的基本上就是让div的位置变为-100px到左侧。

and I know I probably shouldn't be asking two questions but why does my footer not extend to the full width of the page I know it has to do with the sidebar but in what way?? 而且我知道我可能不应该问两个问题,但是为什么我的页脚没有延伸到页面的整个宽度,我知道这与边栏有关,但是用什么方式呢?

You can use the code from here: Check if a user has scrolled to the bottom 您可以从此处使用代码: 检查用户是否滚动到底部

The following code hides a div if the page is scrolled 100px from the bottom. 如果页面从底部滚动100像素,则以下代码将隐藏div。

$(window).scroll(function() {
  if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
    $('#myDivId').hide();
  }
  else {
    $('#myDivId').show();
  }
});

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

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