简体   繁体   English

在页脚处停止固定的侧边栏-防止重叠

[英]Stop fixed sidebar at footer - prevent overlapping

A sidebar becomes fixed after 400 pixels from top. 从顶部起400像素后,侧边栏将变为固定。 Therefore I use this code found on stack: 因此,我使用在堆栈上找到的以下代码:

<div id="gettop"></div>

<script type="text/javascript">
jQuery(function($) {
function fixDiv() {
var $cache = $('#gettop');
if ($(window).scrollTop() > 400)
  $cache.css({
    'position': 'fixed',
    'top': '8px',
    'margin-left': '20px',
    'border': '1px solid #ccc'
  });
else
  $cache.css({
    'position': 'relative',
    'top': 'auto'
  });
}
$(window).scroll(fixDiv);
fixDiv();
});

The Code works great. 该规范的效果很好。 But the sidebar is overlapping the footer. 但是侧边栏与页脚重叠。 How can I prevent this? 我该如何预防?

I tried some code I found here without success. 我尝试了一些在这里找到的代码,但没有成功。

How to prevent fixed button from overlapping footer area and stop the button on top of where the footer is located 如何防止固定按钮重叠页脚区域并将按钮停在页脚所在的顶部

Stop fixed position at footer 在页脚处停止固定位置

Fixed sidebar on the scroll stop at div 固定div滚动停止处的侧边栏

I am quite sure, that I made a mistake in mixing the codes. 我很确定,在混合代码时我犯了一个错误。

Thanks for help. 感谢帮助。

尝试为要放在顶部的元素赋予更大的z-index。

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

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