我在使用 scrolltofixed jquery 插件时遇到问题
https://github.com/bigspotteddog/ScrollToFixed
我使用:
$('#tostick').scrollToFixed({ limit: $('#app-footer').offset().top - $('#tostick').height() - 20});
我的#tostick 在一个
margin:0 auto
div 容器,一旦它碰到固定页脚并且脚本从固定定位切换到绝对定位,它就会跳出容器,因为
left: 1107px
被应用,这是到浏览器窗口左边界的距离,而不是居中的 div 容器的左边界。它试图添加:
offsetLeft: -$('#container').offset().left
这完全被忽略了。 提前感谢任何提示!
最佳答案
您需要提供更多我们不知道#tostick 是什么的信息。显然我们需要整个 JS,以及相关的 html 和 css。您是否尝试过移动整个容器 div 它的唯一目的是拥有 margin:0 auto 的样式? 你也可以这样做:
$('#tostick').bind('unfixed', function() { $(this).css('left', ''); });//or what it needs to look right
$('#tostick').bind('fixed', function() { $(this).css('left', '1107px'); });//switch back to what it was
关于javascript - scrolltofixed 插件切换到位置 : absolute 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9159538/