2013-04-06 57 views
2

我有一個像以下模型的HTML頁面,如何計算可見的高度?

當用戶正在滾動頁面時,如何計算#page1的可見部分的高度?

------------------------------------------------------- 
#heder (position: fixed; height: 100px, z-index: 10) 
------------------------------------------------------- 

        visible zone 

____________________________________________________ 
|             | 
|     #page1 (visible)    | 
|             | 
| (position: static; height: 1000px, z-Index: 0) | 
|             | 
------------------------------------------------------- 
#footer (position: fixed; height: 50px, z-index: 10) 
------------------------------------------------------- 
|             | 
|             | 
|             | 
|             | 
|     #page1 (invisible)    | 
|             | 
|             | 
|             | 
|             | 
____________________________________________________ 
|             | 
|             | 
|             | 
|     #page2 (invisible)    | 
|             | 
| (position: static; height: 700px, z-Index: 0) | 
|             | 
|             | 
|             | 
|             | 
|             | 
____________________________________________________ 
+2

我認爲這有你在找什麼:http://stackoverflow.com/questions/12868287/get-height-of-visible-portion-of-div – smerny 2013-04-06 03:13:22

回答

1

您可以通過在jQuery的使用window.top得到最窗口的高度。 window.top的高度將獲得瀏覽器窗口或其內部的iframe的高度。

$(window.top).height();