固定浮动元素在页脚处停止
我使用了 http://jqueryfordesigners.com/fixed-floating-elements 中的代码滚动到某个点后浮动元素。这是我正在开发的网站: http://bodyecology.com/articles/gut-type -update
如您所见,滚动时右列变得固定,但在页脚处重叠。我怎样才能让它停在页脚上方?
目前使用:
<script>
jQuery(document).ready(function () {
var top = jQuery('#news_sidebar').offset().top - parseFloat(jQuery('#news_sidebar').css('marginTop').replace(/auto/, 0));
jQuery(window).scroll(function (event) {
var y = jQuery(this).scrollTop();
if (y >= top) {
jQuery('#news_sidebar').addClass('fixed');
} else {
jQuery('#news_sidebar').removeClass('fixed');
}
});
});
</script>
I've used the code from http://jqueryfordesigners.com/fixed-floating-elements to float an element after scrolling to a certain point. Here is the site I'm working on: http://bodyecology.com/articles/gut-type-update
As you can see, the right column becomes fixed when scrolled, but overlaps at the footer. How can I cause it to stop at just above the footer?
Currently Using:
<script>
jQuery(document).ready(function () {
var top = jQuery('#news_sidebar').offset().top - parseFloat(jQuery('#news_sidebar').css('marginTop').replace(/auto/, 0));
jQuery(window).scroll(function (event) {
var y = jQuery(this).scrollTop();
if (y >= top) {
jQuery('#news_sidebar').addClass('fixed');
} else {
jQuery('#news_sidebar').removeClass('fixed');
}
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个小提琴可以满足您的需求:
http://jsfiddle.net/ZczEt/9/
这里是处理右侧浮动元素 $('#summary') 的 javascript:
这是 jquery 插件及其来源:
https://github.com/bigspotteddog/ScrollToFixed
This fiddle does what you are looking for:
http://jsfiddle.net/ZczEt/9/
Here is the javascript that handles the floating element $('#summary') on the right:
Here is the jquery plugin and its source:
https://github.com/bigspotteddog/ScrollToFixed
我有和你一样的代码来浮动我的div
来自同一篇文章“Fiding-Floating-Elements”
并且与重叠页脚有同样的问题,对我有用的唯一解决方案(我是一个 javascript newvie)是使用以下代码将 div 从页脚中拉开:
这对我很有帮助,我希望其他人也会发现它有帮助:)
我已经在我的网站上实现了它,以便用户可以获得完整文章视图
i have the same code as you to float my div
from the same post "Fixing-Floating-Elements"
and had the same problem as you have with the overlapping footer, the ONLY solution working for me (i'm a javascript newvie) was pulling the div away from the footer with this code:
This was helpful to me i hope someone else will find it helpful :)
I've implemented it on my site so the users can get full articles view
我可能是错的,但这似乎是右侧边栏中内容的大小。它会重叠,因为它太大,当您滚动到底部时不会重叠。
您可以在底部设置与顶部相同的止损并重新定位。当您滚动到顶部时,它会重新定位自己。页脚也尝试一下。
I could be wrong, but it appears to be the size of the content inside the right sidebar. It overlaps because its too big not to when you scroll to the bottom.
You could put the same stop and re-position at the bottom as you do on top. When you scroll to the top, it re-positions itself. Try that for the footer as well.