2016-05-31 57 views
0

屏幕視口使用$(window).height()我計算我的視口的大小,它返回339 現在我想把我的屏幕分成三部分。上,中,下。我想知道如何知道返回的屏幕高度是如何計算的。

我想知道總數(339)中有多少個px會覆蓋頂部的20%,中間的60% 20%的底部。我如何計算這個?任何人都可以幫助我嗎?另外,我的方法是對的嗎?

enter image description here

回答

0

數學是非常簡單的:

(winH = 339)

0.6 * winH = middleH(203.4)
0.2 * winH =至pH,兩者(67.8)

但是嘿!爲什麼你需要jQuery?

html, body{height:100%; margin:0;} 
 

 
#top, 
 
#bot{ 
 
    height:20vh; 
 
    background:#0bf; 
 
} 
 
#mid{ 
 
    height:60vh; 
 
    background:#f0b; 
 
}
<div id="top"> top </div> 
 
<div id="mid"> mid </div> 
 
<div id="bot"> bot </div>

+0

其實,我想主力店,在jQuery的變量中,底部的像素值。我有一個HTML元素,我想比較它的「位置」與這些變量。例如,'if($(element).position

+0

因此,如果我的元素位於底部區域,我將如何知道? –

+0

基本上,這個解決方案http://stackoverflow.com/questions/37485342/popover-auto-adjust-placement我想獲得我的屏幕的頂部,中間和底部區域,所以我可以比較我的元素在哪裏 –