[ 2 posts ]

Marco Asbreuk

YUI Contributor

  • Username: itsasbreuk
  • Joined: Mon Nov 16, 2009 5:14 am
  • Posts: 457
  • Location: Netherlands
  • Twitter: itsasbreuk
  • GitHub: ItsAsbreuk
  • Gists: ItsAsbreuk
  • IRC: Marco Asbreuk
  • Offline
  • Profile
Tags:

How to detemine node's height with absolute-pos child-divs

Post Posted: Sun Apr 24, 2011 1:59 pm
+0-
Has anybody a clue how I can determine the node's height when there are absolute positioned divs within?
Code:
<div id='div1' style='height:200px'>
<div id='div2' style='position:absolute; height:200px; top:50px;'>
</div>
<div id='div3' style='position:absolute; height:200px; top:150px;'>
</div>
</div>
I would like to get the value of 350px when refering to div1.
I don't see a standard functioncall. So I tried something like:
Code:
absNodeHeight : function(node) {
    var finalHeight = node.get('offsetHeight');
    var divlist = node.all('DIV');
    divlist.each(function() {
       var subNodeHeight = absNodeHeight(this)+this.getStyle('top');
       if (subNodeHeight>finalHeight) {finalHeight=subNodeHeight;}
    });
    return finalHeight;
}
But this doesn't work of course, due to the function each, which loses its reference to the function it is called from (finalHeight is unknown at this point).

Kind Regards,
Marco.

Marco Asbreuk

YUI Contributor

  • Username: itsasbreuk
  • Joined: Mon Nov 16, 2009 5:14 am
  • Posts: 457
  • Location: Netherlands
  • Twitter: itsasbreuk
  • GitHub: ItsAsbreuk
  • Gists: ItsAsbreuk
  • IRC: Marco Asbreuk
  • Offline
  • Profile
Tags:

Re: How to detemine node's height with absolute-pos child-di

Post Posted: Sun May 01, 2011 3:56 am
+0-
I'm using this function now:
But I think it would be nice if there was one alike in the node-module. So I will put a request.

Code:
function getRealHeight(node) {
// returns the real nodeheight, also taken into account absolute or relative divs that float above the node
    var startY = parseInt(node.getY(), 10);
    var finalY = parseInt(node.get('offsetHeight'), 10) + startY;
    var childList = node.all('DIV');
    var listSize = childList.size();
    var i, childNode, position, childY;
    for (i=0; i<listSize; i++) {
        childNode = childList.item(i);
        position = childNode.getStyle('position');
        if ((position==='absolute') || (position==='relative')) {
           childY = parseInt(childNode.get('offsetHeight'), 10) + parseInt(childNode.getY(), 10);
           if (childY>finalY) {finalY=childY;}
        }
    }
    return finalY-startY;
}
  [ 2 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
cron