2012-06-27 54 views
0

我试图根据窗口中的滚动位置修复元素位置。JQuery偏移量和ScrollTop问题

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

看起来好像该元素的偏移大于scrollTop最大数字。

是否有任何其他方式让这个工作?

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

http://be.blackberry.com/

但我不想要克隆的元素,我想检测当它到达靠近页面的底部,然后改变元素的底部位置。

在此先感谢。

回答

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); 
    } 
});