【问题标题】:Keep footer sticked to bottom when scrolling outside of the page在页面外滚动时保持页脚底部
【发布时间】:2018-06-28 18:02:04
【问题描述】:

我制作了一个粘性页脚,当页面当前未滚动时效果很好。 但是为了动画 safari 和 chrome(也许还有其他)正在将我的页面移到其内容之外。这是一个在到达页面末尾时不会突然停止滚动的功能。 这是它的样子。

我怎样才能设法用我的页脚隐藏页面的外部?我想让它变成灰色,就像我的页脚一样。但它是白色的,我们可以看到我的蓝色侧边栏。这真的很丑。

有什么想法吗?

编辑:

这里是我用来使它变得粘稠的 Css

footer{
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 50px;
    background-color: #434343;
    color: white;
    font-size: 12px;
    text-align: center;
    z-index:200;
}

我尝试使用 margin-bottom 负数使其更长,但导航器滚动更多,只是将问题向前移动了一些像素。

当然,我不希望滚动时有固定的页脚。 问题实际上是页面边缘的beaucoup。以及到达时的动画。

编辑2:

Here an sample code if you want to play with it

当我滚动太多时看到的内容(我不希望页脚后面的白色部分)

【问题讨论】:

  • 任何代码要显示?
  • 对于那些不熟悉的人,如果您到达页面底部但“继续滚动”,您会看到此视觉提示,表明您无法再滚动(滚动变得迟缓)。似乎是浏览器/操作系统实现。这似乎相关:stackoverflow.com/questions/44029176/….
  • 发布您的代码,可能会提供更好的答案。
  • 我认为最好的办法是让页脚更长
  • @Chris 是的,确实它似乎是相关的,但我没有看到我的问题的直接解决方案

标签: html css


【解决方案1】:

这里有一个解决方案。我做了一个简单而不是真正的页脚。但是当我滚动时,几乎不可能看到蓝色 div 之后的白色部分。这就是我想要的。

最后的问题是:它是最优的吗?我们可以不使用 js 吗?

window.onscroll = function(ev) {
    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        //alert("you're at the bottom of the page");
        $('#footer').show();
    }
    else{
        $('#footer').hide();
    }
};
.footer{
  background-color:red;
  width:100%;
  height: 50px;
  display:none;
  position:fixed;
  bottom:0;
  z-index:-1;
}

.rectangle{
  background-color:blue;
  width:100%;
  height: 50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<br>
<br><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed dictum justo ac tellus placerat, nec lacinia urna iaculis. Vestibulum eget tincidunt justo. Maecenas facilisis lectus at eros scelerisque, id bibendum risus gravida. Sed id ligula pharetra, lacinia nibh sit amet, ultrices tortor. Mauris vitae tortor rutrum, volutpat turpis sit amet, lobortis nunc. Pellentesque convallis est diam, sed vehicula lacus tempor ac. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<div class="rectangle"></div>
<div id="footer" class="footer"></div>

【讨论】:

  • 现在看我的回答,这次我答对了吗?
【解决方案2】:

您是否尝试过使用相应的 div 进行以下操作,或者分享您的代码以获得更好的答案。

     position:fixed;
     bottom: 0;
     width: 100%;

【讨论】:

  • 很抱歉不清楚,但我认为您提供了一个固定的页脚。看看我的代码。
猜你喜欢
  • 2022-11-23
  • 2015-07-12
  • 2017-02-12
  • 2013-07-27
  • 1970-01-01
  • 2016-06-17
  • 1970-01-01
  • 2021-07-15
相关资源
最近更新 更多