Foros del Web » Programando para Internet » Javascript »

Calcular el height del DIV de contenido

Estas en el tema de Calcular el height del DIV de contenido en el foro de Javascript en Foros del Web. Hola El caso es el siguiente, tengo dos columnas DIV una a la izquierda y otra a su derecha, el DIV de la izquierda corresponde ...
  #1 (permalink)  
Antiguo 08/09/2006, 06:32
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
Calcular el height del DIV de contenido

Hola

El caso es el siguiente, tengo dos columnas DIV una a la izquierda y otra a su derecha, el DIV de la izquierda corresponde al menú de la página y el DIV de la derecha es más ancho y corresponde al contenido dinámico del sitio, este ultimo su altura es variable, depende del contenido que muestra de la base de datos (es de height auto).


Necesito poder calcular mediante onload el height de DIV de contenido para que el DIV de la derecha ajuste su altura en forma automatica al contenido de otro DIV.

Es posible con js?

se me ocurre algo por el estilo pero no se como hacerlo con js:
  1. Luego de que ha cargado por completo la página (evento onload) debería capturar la altura actual de ambos DIV's
  2. Comparar ambas alturas para ver cual de las 2 es mayor
  3. Al que tiene menor altura se debería asignar la misma altura que el otro. Esto se debería lograr redefiniendo su altura mediante CSS (utilizando Javascript).

desde ya muchas gracias


salu2

zsamer
  #2 (permalink)  
Antiguo 08/09/2006, 08:07
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Hola zsamer

Prueba poniendo un id al div: <div id="algo">

y utilizando este código:

alto = document.getElementById('algo').offsetHeight;

Saludos,
  #3 (permalink)  
Antiguo 08/09/2006, 09:48
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
gracias, pero no soy muy experto en el tema, como se tendría que hacer.

este es el codigo:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title>footerStick Footer sticks to bottom of page</title>

<
style>
html,body {
    
height:100%;
}

#contenedor{
    
width100%;
    
heightauto;
    
background-color#999999;
    
border1px solid red;
}


#menu_izda{
    
floatleft;
    
width250px;
    
margin0;
    
background-colorred;
    
height100%;
    
border1px solid blue;
}


#contenido{
    
margin-left254px;
    
heightauto;
    
background-color:#cccccc;
    
border1px solid yellow;
}

</
style>

</
head>

<
body>

<
body>
 <
div id="contenedor">

    <
div id="menu_izda">
    
Left Col<br>
    
This is content of the LEFT columnIt can be shortlonger or very longThis is content of the LEFT columnIt can be shortlonger or very longThis is content of the LEFT columnIt can be shortlonger or very long.
    </
div>


    <
div id="contenido">
        
Contenido<br>
        
This is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very long.
        
This is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very longThis is content of the MIDDLE columnIt can be shortlonger or very long.
    </
div>


</
div>
</
body>
</
html
como y donde tendria que aplicar el

Código PHP:
alto document.getElementById('algo').offsetHeight
gracias

salu2
  #4 (permalink)  
Antiguo 08/09/2006, 14:45
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
algun alma caricativa?
  #5 (permalink)  
Antiguo 09/09/2006, 23:59
Avatar de chalchis  
Fecha de Ingreso: julio-2003
Mensajes: 1.773
Antigüedad: 20 años, 9 meses
Puntos: 21
ya sea que lo pongas asi

dentro de head

<script>
function redimensionar()
{
document.getElementById('algo').offsetHeight;
}
</script>

y en en body pon asi
<body onload='redimensionar()'>

o la otra es poner despues del cierre del body
</body>
<script>
document.getElementById('algo').offsetHeight;
</script>

porque la anterior opcion puede que marque el error ya que el div aun no se dibuja pero has las pruebas

saludos
__________________
gerardo
  #6 (permalink)  
Antiguo 10/09/2006, 05:12
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Puedes hacerlo como te sugiere chalchis pero que la función sea algo así


function redimensionar()
{
alto = document.getElementById('div1').offsetHeight;
document.getElementById('div2').style.height = alto + 'px'
}

donde div1 es el contenedor del cual quieres saber la altura y div2 el contenedor que quieres redimensionar

un saludo
  #7 (permalink)  
Antiguo 10/09/2006, 10:26
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
ok se pasaron, muchas gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:53.