Jquery 固定浮动元素停止在页脚
我使用了中的代码在滚动到某个点后浮动元素。以下是我正在工作的网站: 如您所见,右列在滚动时变为固定列,但在页脚处重叠。我怎样才能使它停在页脚的正上方 目前正在使用:Jquery 固定浮动元素停止在页脚,jquery,css,scroll,footer,css-position,Jquery,Css,Scroll,Footer,Css Position,我使用了中的代码在滚动到某个点后浮动元素。以下是我正在工作的网站: 如您所见,右列在滚动时变为固定列,但在页脚处重叠。我怎样才能使它停在页脚的正上方 目前正在使用: <script> jQuery(document).ready(function () { var top = jQuery('#news_sidebar').offset().top - parseFloat(jQuery('#news_sidebar').css('marginTop').repl
<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>
jQuery(文档).ready(函数(){
var top=jQuery('news_边栏').offset().top-parseFloat(jQuery('news_边栏').css('marginTop').replace(/auto/,0));
jQuery(窗口).滚动(函数(事件){
var y=jQuery(this.scrollTop();
如果(y>=顶部){
jQuery(“#新闻_边栏”).addClass('fixed');
}否则{
jQuery(“#新闻_边栏”).removeClass('fixed');
}
});
});
我可能错了,但它似乎是右侧边栏中内容的大小。它重叠是因为它太大了,当您滚动到底部时,它不会消失
您可以在底部放置与在顶部相同的停止和重新定位。当您滚动到顶部时,它会重新定位自身。也可以在页脚上试试。这把小提琴可以满足您的需要: 下面是处理右侧浮动元素$(“#summary”)的javascript:
$('#summary').scrollToFixed({
marginTop:
$('.header').outerHeight() + 10,
limit:
$('.footer').offset().top -
$('#summary').outerHeight() -
10
});
以下是jquery插件及其来源:
我有与您相同的代码来浮动我的div 来自同一篇文章“固定浮动元素” 与重叠页脚的问题相同,唯一适合我(我是javascript newvie)的解决方案是使用以下代码将div从页脚中拉出:
$(window).scroll(function () {
// distance from top of footer to top of document
footertotop = ($('#footer').position().top);
// distance user has scrolled from top, adjusted to take in height of sidebar (570 pixels inc. padding)
scrolltop = $(document).scrollTop() + 570;
// difference between the two
difference = scrolltop - footertotop;
// if user has scrolled further than footer,
// pull sidebar up using a negative margin
if (scrolltop > footertotop) {
$('#cart').css('margin-top', 0 - difference);
}
else {
$('#cart').css('margin-top', 0);
}
});
这对我很有帮助,我希望其他人会觉得这很有帮助:)
我已经在我的网站上实现了它,所以用户可以得到是的,我改变了它,所以它没有那么大。假设您的视口小得多,元素将与页脚重叠。我想让它变大,但让它停在页脚之前。我将向脚本添加什么以在页脚处停止它?我已添加此页面作为我要执行的操作的示例:。请注意,元素现在变长了,所以它与页脚重叠。@bigspotteddog我很不好意思如此无耻地劫持这个评论线程,但我想不出另一种方法来私下向您发送消息。我正在努力正确使用你的插件scrolltofixed。如果你能快速看一眼,我将永远感激你。@Billmalaky我已经回应了你无耻地被劫持的评论:)关于你上面链接的问题。