也许这可能是一个更好的样本. HTML和CSS代码基于您的原始问题.长内容示例包含在DIV中,只是为了给出比浏览器窗口高度更长的内容.您可以用纯文本或任何东西替换整个DIV容器.
function checkOffset() {
var a=$(document).scrollTop()+window.innerHeight;
var b=$('#footer').offset().top;
if (a
$('#social-float').css('bottom','10px');
} else {
$('#social-float').css('bottom',(10+(a-b))+'px');
}
}
$(document).ready(checkOffset);
$(document).scroll(checkOffset);
#social-float {
position: fixed;
bottom: 10px;
left: 10px;
width: 55px;
padding: 10px 5px;
text-align: center;
background-color: #fff;
border: 5px solid #ccd0d5;
border-radius: 2px;
}
#footer { height: 5em; background: #888; }
long content sample