JQuery Offset和ScrollTop问题

时间:2012-06-27 13:21:21

标签: javascript jquery

我正在尝试根据窗口中的滚动位置修复元素位置。

我认为这就像获取固定元素应该固定的元素的偏移一样容易,然后当window.scrollTop等于它时添加CSS但是很奇怪。

似乎元素的偏移量大于scrollTop最大数字。

还有其他方法可以让它发挥作用吗?

我希望它具有与滚动页脚相同的功能;

http://be.blackberry.com/

但我不想克隆元素,我想检测它何时到达页面底部附近,然后更改元素底部的位置。

提前致谢。

1 个答案:

答案 0 :(得分:0)

这应该有助于您朝着正确的方向前进:

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 );
    }
});
相关问题