Ver Mensaje Individual
  #8 (permalink)  
Antiguo 31/12/2009, 09:26
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Como obtener dinamicamente el siguiente nivel con JS

Es bastante diferente a actionScript (donde tampoco es muy recomendable usar getNextHighestDepth, mejor usar DepthManager, pero claro, es cuestión de gustos).
En javascript, sólo los elementos posicionados con propiedad position diferentes a static son susceptibles de manejar z-index (zIndex para javascript). Además, el valor máximo de z-index varía para los diferentes navegadores: http://softwareas.com/whats-the-maximum-z-index.
Otra cuestión a considerar para poder acceder a los valores de z-index es si se definieron con el atributo style o si se definieron en hojas de estilo o tags style. Si se definieron con style podrías acceder a su valor con elemento.style, pero si no, tandrías que usar los estilos computados (getComputedStyle o currentStyle para explorer).
Pero en general, podrías usar algo como esto para emular esa funcionalidad:
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>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
<
style>
#dd{ position:absolute; z-index:200}
</style>
<
script>
function 
css(o,prop){
    if(
window.getComputedStyle){
        return 
document.defaultView.getComputedStyle(o,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 
o.currentStyle[prop] ? o.currentStyle[prop] : null;
    }
}  
function 
getNextHighestDepth(){
    var 
col=document.getElementsByTagName('*'),l=col.length,i,mx=0,t;
    for(
i=0;i<l;i++){
        
t=parseInt(css(col[i],'z-index'));
        if(
&& t>mx)
            
mx=t;
    }
    return 
mx+1;
}
onload=function(){
    
alert(getNextHighestDepth());
}
</script>
</head>

<body>
<div id="pp" style="position:absolute; z-index:100">Colocar aquí el contenido para  id "pp"</div>
<div id="dd">Colocar aquí el contenido para  id "dd"</div>
<p>nada</p>

</body>
</html> 

Última edición por Panino5001; 31/12/2009 a las 09:35