简体   繁体   English

浮动页脚仅在用户向下滚动 200 像素后出现

[英]Floating footer to only appear once user has scrolled down 200px

I'm building a site which requires a Footer which will float at the bottom of the browser window at all times.我正在构建一个需要页脚的站点,该页脚将始终浮动在浏览器 window 的底部。

However, this should only appear once the user has scrolled down 200px.但是,这只会在用户向下滚动 200 像素后出现。 It should then scroll in place (as if the footer is attached to the content 200px out of view, but attaches itself to the browser window).然后它应该就地滚动(就好像页脚附加到 200 像素外的内容,但自身附加到浏览器窗口)。

As soon as the user scrolls back up, this needs to then be hidden again.一旦用户向上滚动,就需要再次隐藏它。

How can this be done?如何才能做到这一点?

Maybe this piece of code can help you out:也许这段代码可以帮助你:

$(window).scroll(function() {
    if ($(this).scrollTop() < 200) {
        $("#footer").hide();
    }
    else {
        $("#footer").show();
    }
});

and for the CSS add对于 CSS 添加

#footer {
    position:fixed;
    left:0px;
    bottom:0px;
    height:100px;
    width:100%;
    display:none;
}

Something like this:像这样的东西:

$(window).scroll(function() {
  if ($(this).scrollTop() < 200) {
    $("footer").slideUp();
      }
  else {
    $("footer").slideDown();
      }
});

I think http://jsfiddle.net/KEjfe/4/ is what you want, from what I gather in your question.我认为http://jsfiddle.net/KEjfe/4/是你想要的,从我在你的问题中收集到的。

BUT

I want to you to know that the fiddle is a crude example and I had to hack to together because it was in fiddle.我想让你知道小提琴是一个粗略的例子,我不得不一起破解,因为它在小提琴中。 But the idea is there, which is that you make 2 of the same footers.但想法就在那里,那就是你制作 2 个相同的页脚。 One that is in a fixed position (in the fiddle it's absolute), and one that is in a absolute position (in the fiddle it's relative).一个在固定的 position 中(在小提琴中它是绝对的),一个在绝对的 position 中(在小提琴中它是相对的)。 Then you can have the same type of if statement in my fiddle, once you scroll past 200px from the top, remove the absolute positioned and show the fixed, and vice versa when you are below 200px.然后你可以在我的小提琴中使用相同类型的if语句,一旦你从顶部滚动超过 200px,删除绝对定位并显示固定,反之亦然,当你低于 200px 时。

So remember:所以请记住:

  • A div that is fixed positioned (which is the sticky footer)固定位置的 div(即粘性页脚)
  • A div that is absolute positioned (which is the flowing footer)绝对定位的 div(即流动的页脚)

Looks like you need fixed footer .看起来你需要固定的页脚

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

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