2010-04-14 62 views
0

以下Ryan Bates Screencast#114我試圖用原型生成無盡的頁面。與Ryan的展示區別不同,我通過AJAX請求調用的URL應該動態處理,因爲當用戶到達頁面末尾時,我並不總是調用相同的URL。使用原型訪問當前URL使用原型

所以我的JS在運行的底色看起來像,而是使用document.location.href一個固定的網址:

var currentPage = 1; 

function checkScroll() { 
    if (nearBottomOfPage()) { 
    currentPage++; 
    new Ajax.Request(document.location.href + '?page=' + currentPage, {asynchronous:true, evalScripts:true, method:'get'}); 
    } 
    else { 
    setTimeout("checkScroll()", 250); 
    } 
} 

function nearBottomOfPage() { 
    return scrollDistanceFromBottom() < 10; 
} 

function scrollDistanceFromBottom(argument) { 
    return pageHeight() - (window.pageYOffset + self.innerHeight); 
} 

function pageHeight() { 
    return Math.max(document.body.scrollHeight, document.body.offsetHeight); 
} 

document.observe('dom:loaded', checkScroll); 

的問題是:該代碼似乎在Safari中工作,但未能在FF 3.6。看來FF不同地計算scrollHeight或offsetHeight。我怎樣才能防止呢?

Thx提前。 傑森

回答

0

我沒有使用他們自己,但我猜,pageHeight()可以使用document.viewport.getHeight()這應該是一個更準確的/跨瀏覽器的選擇。

+0

Thx的建議。我不得不在很多地方修改Ryan的JS,document.viewport.getHeight()很有用,並且完成了這項工作。 – 2010-05-05 20:15:28