2012-06-27 51 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); 
    } 
});