Foros del Web » Programando para Internet » Javascript »

Transición al mostrar capas

Estas en el tema de Transición al mostrar capas en el foro de Javascript en Foros del Web. Hola, Tengo un script que cada cierto tiempo cambia de una capa a otra, pero lo hace muy brusco. ¿No hay alguna instrucción para que ...
  #1 (permalink)  
Antiguo 17/06/2010, 08:29
Usuario no validado
 
Fecha de Ingreso: marzo-2004
Mensajes: 349
Antigüedad: 20 años
Puntos: 0
Transición al mostrar capas

Hola,

Tengo un script que cada cierto tiempo cambia de una capa a otra, pero lo hace muy brusco. ¿No hay alguna instrucción para que sin tomarse demasiado tiempo suavice la capa que desaparece?

Gracias
  #2 (permalink)  
Antiguo 17/06/2010, 13:11
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 3 meses
Puntos: 126
Respuesta: Transición al mostrar capas

Hola

Puedes usar JQuery o el Dom.

Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var ns4 = (document.layers)? true:false
  5. var ie4 = (document.all)? true:false
  6. var ns6 = (document.getElementById)? true:false
  7. var nivel = 1;
  8. var PosElementoAlto = 0 ;
  9. var Arr = [];
  10.  
  11. var info = {
  12. captura_objeto : function(idnombre) {
  13.     if (ns6)
  14.     {
  15.     return document.getElementById(idnombre);
  16.     }
  17.     else if (ie4)
  18.     {
  19.     return document.all[idnombre];
  20.     }
  21.     else if (ns4)
  22.     {
  23.     return document.layers[idnombre];
  24.     }
  25.     else
  26.     {
  27.     return null;
  28.     }
  29. },
  30.  
  31.  
  32. Evento : function(elemento,nomevento,funcion) {
  33.     if (elemento.attachEvent)
  34.     {
  35.         var fct=function(){
  36.             funcion.call(elemento,window.event);
  37.         }
  38.         elemento.attachEvent('on'+nomevento,fct);
  39.         return true;
  40.     }
  41.     else  
  42.         if (elemento.addEventListener)
  43.         {
  44.         elemento.addEventListener(nomevento,funcion,false);
  45.         return true;
  46.         }
  47.         else
  48.         return false;
  49. },
  50.  
  51.  
  52. init: function(){
  53. var ref = info.captura_objeto('lasLigas').getElementsByTagName('A');
  54.     for (var i = 0; i < ref.length; i++) {
  55. var infodiv = info.captura_objeto('info_menu_'+ref[i].id);
  56.         if (document.Element || document.body) {
  57.             info.altura = infodiv.scrollHeight;
  58.         } else {
  59.             info.altura = infodiv.clientHeight;
  60.         }
  61.             infodiv.style.display = 'none';
  62.             infodiv.style.zIndex = 0;
  63.                     info.Evento(ref[i], 'click', function() {info.efecto_largo(this.id)});
  64.     }
  65. },
  66.  
  67.  
  68. PosicionAbsolutaElemento: function(element)  {
  69. var window_height =  parseInt(((screen.height) / 2) - info.altura);
  70. var window_width = parseInt(((screen.width) / 2) - 150);
  71.  
  72.     if (typeof element == "string")
  73.         element = info.captura_objeto(element)
  74.             if (!element) return { top:0,left:0 };
  75. var y = 0;
  76. var x = 0;
  77.             while (element.offsetParent) {
  78.                     x += element.offsetLeft;
  79.                     y += element.offsetTop;
  80.                 element = element.offsetParent;
  81.      }
  82.     return {top:y, left:x, height:window_height, width: window_width};
  83.  
  84. },
  85.  
  86.    
  87. efecto_largo: function(id){
  88.             if(info.captura_objeto('info_menu_'+id).style.display == 'none'){
  89.                     clearInterval(info.intervalo);
  90.                 info.despliega_largo(id);
  91.         info.abierto_largo = false;
  92. //alert(info.abierto_largo);
  93.             }else{
  94.                     clearInterval(info.intervalo);
  95.                     info.recoge_largo(id);
  96.         info.abierto_largo = true;
  97. //alert(info.abierto_largo);
  98.             }
  99. },
  100.    
  101.  
  102. despliega_largo: function(id){
  103. Arr.unshift(id);
  104. //alert(Arr);
  105.     for (var i = 0; i < Arr.length; i++) {
  106. var infodiv = info.captura_objeto('info_menu_'+Arr[i]);
  107. var PosElemento = info.PosicionAbsolutaElemento(Arr[i]);
  108.         if (i == 0) {
  109. PosElementoAlto = PosElemento.top;
  110.             infodiv.style.height = '1px';
  111.             infodiv.style.display = 'block';
  112.             infodiv.style.zIndex = nivel;
  113.             infodiv.style.left = parseInt(PosElemento.width) +'px';
  114.             infodiv.style.top = parseInt(PosElemento.height - PosElementoAlto) +'px';
  115.                     info.intervalo = setInterval(function(){ info.redimenciona_largo(info.altura,id); }, 1);
  116.             nivel ++;
  117. //alert(parseInt(PosElementoAlto))
  118.         } else {
  119. var izq_arr = parseInt(20 * i) 
  120.             infodiv.style.left = parseInt(PosElemento.width - izq_arr) +'px';
  121.             infodiv.style.top = parseInt((PosElemento.height) - (PosElementoAlto + izq_arr)) +'px';
  122.         }
  123.     }
  124. },
  125.    
  126.  
  127. recoge_largo: function(id){
  128. //alert(id)
  129. var infodiv = info.captura_objeto('info_menu_'+id);
  130. var i, encaja;
  131.     for (i = 0; i < Arr.length; i++) {
  132.         if (Arr[i] == id) {
  133.                 encaja = i;
  134.     break;
  135.         }
  136.     }
  137.     for (var j = 0; j < Arr.length; j++) {
  138.         if (j > encaja ) {
  139. var infodiv2 = info.captura_objeto('info_menu_'+Arr[j]);
  140. var PosElemento = info.PosicionAbsolutaElemento('info_menu_'+Arr[j]);
  141.             infodiv2.style.left = parseInt(PosElemento.left + 20) +'px';
  142.             infodiv2.style.top = parseInt(PosElemento.top + 20) +'px';
  143.  
  144.         }
  145.     }
  146.     Arr.splice(encaja, 1);
  147.             infodiv.style.height = info.altura + 'px';
  148.     info.intervalo = setInterval(function(){ info.redimenciona_largo(0,id); }, 1);
  149. },
  150.    
  151.  
  152. redimenciona_largo: function(limite,id){
  153. var infodiv = info.captura_objeto('info_menu_'+id);
  154.     inicial = parseInt(infodiv.style.height);
  155.             actual = Math.ceil((limite - inicial) / 4);
  156.             inicial += actual;
  157.             infodiv.style.height = inicial + 'px';
  158.         if (parseInt(inicial) >= (limite - 5) && parseInt(inicial) <= (limite + 5)) {
  159.             if (info.abierto_largo == false) {
  160.                 infodiv.style.height = limite + 'px';
  161.                 clearInterval(info.intervalo);
  162.             } else {
  163.                 infodiv.style.height = '0px';
  164.                 infodiv.style.display = 'none';
  165.                 clearInterval(info.intervalo);
  166.             }
  167.         }
  168. },
  169.    
  170.  
  171. z_Index : function(id){
  172. // RECOGER
  173. var infodiv = info.captura_objeto('info_menu_'+id);
  174. var i, encaja;
  175.     for (i = 0; i < Arr.length; i++) {
  176.         if (Arr[i] == id) {
  177.                 encaja = i;
  178.     break;
  179.         }
  180.     }
  181. //alert(encaja);
  182.     for (var j = 0; j < Arr.length; j++) {
  183.         if (j > encaja) {
  184. var infodiv2 = info.captura_objeto('info_menu_'+Arr[j]);
  185. var PosElemento = info.PosicionAbsolutaElemento('info_menu_'+Arr[j]);
  186.             infodiv2.style.left = parseInt(PosElemento.left + 20) +'px';
  187.             infodiv2.style.top = parseInt(PosElemento.top + 20) +'px';
  188.  
  189.         }
  190.     }
  191.     Arr.splice(encaja, 1);
  192.  
  193.  
  194. //MOSTRAR
  195. Arr.unshift(id);
  196.  
  197.     for (var i = 0; i < Arr.length; i++) {
  198. var PosElemento = info.PosicionAbsolutaElemento(Arr[i]);
  199. var infodiv = info.captura_objeto('info_menu_'+Arr[i]);
  200. //if (PosElemento.top == 0) PosElemento.top = 9;
  201.         if (i == 0) {
  202.             infodiv.style.zIndex = nivel;
  203.             infodiv.style.left = parseInt(PosElemento.width) +'px';
  204.             infodiv.style.top = parseInt(PosElemento.height - (PosElemento.top + PosElementoAlto)) +'px';
  205.             nivel ++;
  206. //alert(parseInt(PosElementoAlto))
  207.         } else {
  208. //var infodiv = info.captura_objeto('info_menu_'+Arr[i]);
  209. var izq_arr = parseInt(20 * i)
  210.             infodiv.style.left = parseInt(PosElemento.width - izq_arr) +'px';
  211.             infodiv.style.top = parseInt(PosElemento.height - (PosElementoAlto + izq_arr)) +'px';
  212.         }
  213.     }
  214. },
  215.  
  216. abierto_largo : true,
  217. abierto_ancho : true
  218. }
  219.  
  220. info.Evento(window, 'load', info.init);
  221. </script>
  222. </head>
  223. <body>
  224. <div id="lasLigas">
  225. <a href="javascript:void(0);" id="1">MOTOCICLETAS</a> ||
  226. <a href="javascript:void(0);" id="2">COCHES</a> ||
  227. <a href="javascript:void(0);" id="3">AVIONES</a> ||
  228. <a href="javascript:void(0);" id="4">BARCOS</a>
  229. </div>
  230.  
  231. <div id="info_menu_1" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  232. <span style="float:right;"><a href="#" onclick="info.z_Index(1)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(1)" title="Cierra">X</a></span> MUESTRAS DE MOTOCICLETAS<br /><br />
  233. Un texto que quiero ocultar y mostrar con el botón 1<br />
  234. Un texto que quiero ocultar y mostrar con el botón 1<br />
  235. Un texto que quiero ocultar y mostrar con el botón 1<br />
  236. Un texto que quiero ocultar y mostrar con el botón 1
  237. </div>
  238.  
  239.  
  240. <div id="info_menu_2" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  241. <span style="float:right;"><a href="#" onclick="info.z_Index(2)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(2)" title="Cierra">X</a></span> MUESTRAS DE COCHES<br /><br />
  242. Un texto que quiero ocultar y mostrar con el botón 2<br />
  243. Un texto que quiero ocultar y mostrar con el botón 2
  244. </div>
  245.  
  246.  
  247. <div id="info_menu_3" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  248. <span style="float:right;"><a href="#" onclick="info.z_Index(3)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(3)" title="Cierra">X</a></span> MUESTRAS DE AVIONES<br /><br />
  249. Un texto que quiero ocultar y mostrar con el botón 3<br />
  250. Un texto que quiero ocultar y mostrar con el botón 3<br />
  251. Un texto que quiero ocultar y mostrar con el botón 3<br />
  252. Un texto que quiero ocultar y mostrar con el botón 3<br />
  253. Un texto que quiero ocultar y mostrar con el botón 3
  254. </div>
  255.  
  256.  
  257. <div id="info_menu_4" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  258. <span style="float:right;"><a href="#" onclick="info.z_Index(4)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(4)" title="Cierra">X</a></span> MUESTRAS DE BARCOS<br /><br />
  259. Un texto que quiero ocultar y mostrar con el botón 4<br />
  260. Un texto que quiero ocultar y mostrar con el botón 4<br />
  261. Un texto que quiero ocultar y mostrar con el botón 4<br />
  262. Un texto que quiero ocultar y mostrar con el botón 4
  263. </div>
  264. </body>
  265. </html>

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />

Etiquetas: capas
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 21:47.