04/08/2009, 17:02
|
| Me alejo de Omelas | | Fecha de Ingreso: mayo-2004 Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años, 7 meses Puntos: 834 | |
Respuesta: ancho y alto de elemento oculto Probá algo así:
Código:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style>
#contenedor{width:300px; display:none}
</style>
<script>
function css(el,prop){
if(window.getComputedStyle){
return document.defaultView.getComputedStyle(document.getElementById(el),null).getPropertyValue(prop);
}else{
var re = /(-([a-z]){1})/g;
if (prop == 'float') prop = 'styleFloat';
if (re.test(prop)) {
prop = prop.replace(re, function () {
return arguments[2].toUpperCase();
});
}
return document.getElementById(el).currentStyle[prop] ? document.getElementById(el).currentStyle[prop] : null;
}
}
function medidas(el){
var test=document.getElementById(el).cloneNode(true);
test.style.position='absolute';
test.style.left='-1500px';
var ancho=parseInt(css(el,'width'))>0?css(el,'width'):css(document.getElementById(el).parentNode.id,'width');
test.style.width=ancho;
document.getElementsByTagName('body')[0].appendChild(test);
var medidas={w:test.offsetWidth,h:test.offsetHeight}
document.getElementsByTagName('body')[0].removeChild(test);
return medidas;
}
</script>
</head>
<body>
<div id="contenedor">
<div id="elemento">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
<div onclick="var m=medidas('elemento');alert('w:'+m.w+'--h:'+m.h)" style="background-color:#CCC; padding:3px; text-align:center; width:150px; cursor:pointer; font-size:12px">averiguar medidas de elemento</div>
</body>
</html>
|