2013-12-10 20 views
3

我想要2小時以找到AngularJS的整個文檔。使用angularjs 1.2.4獲取文檔高度(不是身體)

我發現很多關於身體高度的問題,但是對於整個文檔沒有任何問題。

使用jQuery,我使用$(document).height並且玩的遊戲,但是使用angularjs我可以有$ window.height但是如果我嘗試$ document.height,函數返回「undefined」。

我用AngularJS 1.2.4

回答

3

http://james.padolsey.com/javascript/get-document-height-cross-browser/

function getDocHeight() { 
    return Math.max(
     document.body.scrollHeight, document.documentElement.scrollHeight, 
     document.body.offsetHeight, document.documentElement.offsetHeight, 
     document.body.clientHeight, document.documentElement.clientHeight 
    ); 
} 
+0

您的代碼返回身體的高度......而不是整個頁面。例如,我的窗口使550px和我的文檔2220(實際上,但它是可變的)和你的函數返回550. – harkor

+0

我很抱歉,內容後我得到的身高。 =) 謝謝! – harkor

+0

這實際上適用於任何前端代碼,而不是指定的角度。 –