我正在尝试根据窗口中的滚动位置来确定元素的位置。
我以为这和获取元素的偏移量一样简单,其中固定的元素应该是固定的,然后当window.scrollTop等于它时,添加CSS,但这很奇怪。
元素的偏移量似乎比scrollTop最大的数字还要大。
有没有其他方法可以让它工作呢?
我希望它有与此相同的功能,关于页脚滚动;
http://be.blackberry.com/
但我不想克隆元素,我想检测它何时接近页面底部,然后更改元素底部的位置。
提前谢谢。
B
发布于 2012-06-27 22:46:02
这应该会帮助你找到正确的方向:
var footer = $("#footer");
// min amount to show when not scrolled to the bottom of the page.
var minVisable = 25;
$(parent.document).scroll(function() {
// check position
if (window.scrollY + window.innerHeight + minVisable > $("html").height()) {
// if at the bottom of the page, stick the footer to it
footer.css("position","absolute").css("top", $("html").height() - footer.height());
} else {
// else keep top part of footer on the screen
footer.css("position","fixed").css("top", window.innerHeight - minVisable );
}
});
https://stackoverflow.com/questions/11227215
复制相似问题