如何让scrollToFix插件限制停在我网站的页脚?

我在我的网站上使用scrollToFix脚本来修复广告,因为用户向下滚动页面以及当用户到达页脚时释放(以便广告不与页脚重叠)。 但是,下面的代码会导致广告停止在页面的三分之一和一半之间滚动,而不是在页脚处。 将其设置为滚动到容器的outerHeight减去页脚的高度,使其停止在该位置。

$(document).ready(function() { $('.right').scrollToFixed({ marginTop: $('.float').outerHeight() + 8, limit: $('footer').offset().top }); }); 

有没有关于如何更准确地停止它的想法?

这可能是因为您的网站在文档准备好后由于字体和图像等而更改高度。尝试将事件绑定到窗口load事件。

 $(function() { $('window').on('load', function() { $('.right').scrollToFixed({ marginTop: $('.float').outerHeight() + 8, limit: $('footer').offset().top }); }); }); 
 $(document).ready(function() { $('.right-sidebar').scrollToFixed({ marginTop: 0, limit: $('.right-sidebar-parent').outerHeight() - 180 } ); }); 

这对我来说是动态限制高度的。