我目前在我的网站上实现了一个“单击以向上滚动”按钮,该按钮本身工作正常,但我唯一的问题是,当它到达页脚时,它会与它重叠。我希望按钮不与项目重叠,并在设定距离处停在页脚顶部。
这是我当前的按钮 CSS:
.back-to-top {
position: fixed;
right: 25px;
display: none;
z-index: 99;
}
这是我的 JS:
$(document).ready(function(){
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
// scroll body to 0px on click
$('#back-to-top').click(function () {
$('body,html').animate({
scrollTop: 0
}, 400);
return false;
});
});
这是在代码笔中:https ://codepen.io/Darlton29/pen/ZEbyNXe
我当然可以调整填充/边距,使其完全避开页脚,但这不是我想要的解决方案,就好像我要扩展页脚一样,我的按钮会在页面上太远。
如您所见,向上滚动按钮与页脚重叠。非常感谢任何帮助。谢谢。
编辑:页脚 CSS
.footer {
position: absolute;
width: 100%;
height: 4rem; /* Set the fixed height of the footer here */
line-height: 4rem; /* Vertically center the text there */
background-color:#292929;
text-align: right;
color: #fff;
padding-right: 2rem;
bottom: 0;
}
慕标5832272
相关分类