Set div height in Javascript

Discussion in 'JavaScript' started by Lafaso870, May 13, 2011.

  1. #1
    Hey everyone,

    I was hoping someone could assist me in find how I could find the offset bottom position of a div. I need the position to set the height of a "filler" div. Depending on the screen size of the user there is a large white space I would like to fill with the "filler" div. I was going to set the height of the "filler" div to the window.document.innerHeight - div offset bottom - footer size. Is this even possible?
     
    Lafaso870, May 13, 2011 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    it is possible but what happens if the user resizes? #badidea
     
    dimitar christoff, May 13, 2011 IP
  3. BennyTran

    BennyTran Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can set : width=100% and height =100%
     
    BennyTran, May 13, 2011 IP
  4. Voynex

    Voynex Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use this code

    
    function calcNodePos(oNode)
    {
    	var yPos = oNode.offsetHeight;
    	do
    	{
    			yPos+= oNode.offsetTop;
    			oNode = oNode.offsetParent;
    	}while( oNode );
    	return yPos;
    }
    Code (markup):
    oNode is the DIV element:
    oNode = document.getElementById("Div_Id");
    Code (markup):
    but I would recommend to go with CSS. JavaScript is not needed here.
     
    Voynex, May 24, 2011 IP
  5. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #5
    you can use this code function calcNodePos(oNode)
    {
    var yPos = oNode.offsetHeight;
    do
    {
    yPos+= oNode.offsetTop;
    oNode = oNode.offsetParent;
    }
    while( oNode );
    return yPos;
    }
     
    unknownpray, Jul 15, 2011 IP
  6. almostamir

    almostamir Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You can add an event listener to check if the window is resized, and resize the filler div accordingly...
     
    almostamir, Jul 17, 2011 IP