因为它是固定在浏览器窗口的固定位置不为我用的情况下工作,您可以在状态得到其中的文字是关闭屏幕的右侧,你不能得到它.无论如何,我试图使用绝对定位然后调整javascript中的"顶部".它在firefox和Chrome中运行得非常好,但在Safari中,滚动时内容会抖动.
<div class="fixed sticky" data-offset-top="50"><p>fixed</p></div>
$(document).ready(function() {
var documentHeight = $(document).height();
$(document).scroll(function() {
var scrollTop = $(window).scrollTop();
$(".sticky").offset(function() {
$this = $(this);
var offsetTop = $this.data("offset-top");
if (scrollTop < 0) {
scrollTop = 0;
}
var newTop = offsetTop + scrollTop;
if (newTop < offsetTop) {
newTop = offsetTop;
}
// Prevents document from infinitely expanding.
var maxTop = documentHeight - $this.height();
if (newTop > maxTop) {
newTop = maxTop
}
// Prevents a bit of jitter since the …Run Code Online (Sandbox Code Playgroud)