滚动页脚底部定位
scrollify footer bottom positioning
已经有一段时间了,我一直在试图自己解决这个问题。我正在使用横向jquery。我总共有五个部分和滚动工作完全没问题。我想让页脚显示在最后一个名为"five"的部分,但它在部分之外。
下面是我的代码:<section class="panel five" data-section-name="five">
<div class="contactus bottom-10">
<!-- IT WAS JUST A CONTACT US FORM, I removed it so the code looks easy and small -->
</div>
<!-- end contact us -->
<div id="footer-wrapper">
<footer>
<!-- FOOTER CODES -->
</footer>
</div> <!--end footer wrapper -->
</section>
CSS #footer-wrapper {
width:100%;
position:absolute;
bottom:0;
height: 50px;
}
部分jquery
$(function () {
$(".panel").css({
"height": $(window).height()
});
$.scrollify({
section: ".panel" //This is the part to detect section ?
});
$(".scroll").click(function (e) {
e.preventDefault();
$.scrollify("move", $(this).attr("href"));
});
});
所以基本上我想把footer-wrapper放到第五部分的页面底部。但事实是,它超出了部分范围。移除绝对会使页脚向上,并在底部形成一个缺口。我不能给出margin-top因为在不同的屏幕上,它会产生问题。
我已经使用了这个插件名为scrollify - http://codepen.io/gam3ov3r/pen/zrdqy
你试过fixed
而不是absolute
吗?
#footer-wrapper {
width:100%;
position:fixed;/* <== */
bottom:0;
height: 50px;
z-index:999;/* could be useful... */
}
编辑此外,你必须使用JS/JQuery来隐藏/显示它。absolute
和fixed
适用于整个html页面。因此,您必须检测第5节何时显示或不显示,并相应地执行show()/hide() #footer-wrapper。
var isSection5_displayed = /* ... check it here ... */;
if(isSection5_displayed) $("#footer-wrapper").show()
else $("#footer-wrapper").hide();
因此,交易是检测"Section 5 has showed"/"Section has passed hidden"。或者"A section has taken place, section #X", if(X ==5), if(X!=5)…"
将#footer-wrapper设为绝对值,而将设为相对div。这个相对div可以,应该是。因此,# footer-w……是绝对的,相对于section,而不是body,并且你只会在section 5中看到footer。
这只是CSS。
CSS:section5 {
position:relative
}
#footer-wrapper {
/* what you already did */
}
阅读:https://css-tricks.com/absolute-positioning-inside-relative-positioning/
- CSS-如何定位内容数据标题
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- 将视口底部滚动到元素底部
- 在Jquery detachment()和appendTo()之后定位元素
- 困在逻辑中试图定位动态的东西
- HTML5页面底部棒
- 固定位置菜单时滚动,直到它击中一个相对容器的底部
- 绝对定位不适用于Javascript DIV
- 将jQuery放在代码的底部
- javascript跨浏览器确定用户是否滚动到页面底部
- Jquery定位代码并调用它
- 如何在容器中定位旋转的图像
- Highcharts-图表外的图例定位
- .scroll()函数在上次更新后在谷歌chrome中定位闪烁
- javascript移动交叉浏览器确定用户是否滚动到页面底部
- 如何制作固定定位的侧边栏,但仅当它到达底部时
- 如何在页面展开之前和之后的页面底部定位按钮
- 定位顶部父元素的底部元素
- 页脚不会将自己定位在页面底部
- 获取相对定位元素的绝对顶部和底部