English 中文(简体)
如何获得子女元素与超级父母的比例百分比
原标题:How to get the percentage that a child element is proportioned to a super parent

我需要在Div母容器内堆放Div。 父母Div容器也是孩子或父母容器内。

我的问题是,当把divs堆叠成像素时,一切都是好的;然而,如果我需要在一个Divs堆下面或中间滑进去,有时我松开一个像素。我知道不可能有0.3232像素,我假设我在小数点处丢掉一个像素。

我有一套常数,作为Var Pixels_PER_FOOT=25;

如果我有一个像以下这样的结构, 我怎样才能设定一个与超级父母成比例的 儿童元素的百分比?

  <div id="superParent" height= 500px        OR 20 Feet     >



    <div id="anotherParent" height="300px"   OR 12 Feet     >


    <div id="aChild" height=If this div is  3 Feet 
                             I need to get the percentage of 3 foot from 20 foot and        
                              apply                             
                              that percentage to its parent or                 
                               what I am calling the anotherParent


   </div>
   </div>

所以如果 3/20 = 15%。 我需要得到 12/20 = 60%, 这也是我迷失的地方。 因为将 15% 的 儿童元素应用到 儿童元素 是不正确的, 因为它的父母不是我从中获取主要百分比的人数 。

我不能用jQuery来做这个。

问题回答

我已经可以访问每个父体像素, 因为在我的循环中, 每个对象的像素都是从上往下设置的, 取决于它的父体高度, 所以不管我身处何处, 只要我先设定该子体的高度, 我总是可以设定一个子体对象的百分比, 只要我先设定该子体的高度, 然后再尝试获得该百分比 。

this.heightPercent = (this.heightPixels / that.parent.size.heightPixels) * 100;




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签