Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/06/2009, 12:46
Avatar de Wonza99
Wonza99
 
Fecha de Ingreso: marzo-2009
Mensajes: 54
Antigüedad: 16 años
Puntos: 0
Respuesta: Ayuda con texto desplegable.

Cita:
Iniciado por buzu Ver Mensaje
Al parecer tienes que cambiarlo todo.
Hace tiempo escribí este código que hace lo que quieres pero es especificamente para un sitio web por lo que necesitarás adaptarlo a tu propio sitio y a tus propias necesidades. Espero que te sirva por lo menos para darte una idea de como se hace:

Código javascript:
Ver original
  1. var info = {
  2.     addEvent: function(elem, evType, func, useCapture){
  3.         if(elem.addEventListener){
  4.             elem.addEventListener(evType, func, useCapture);
  5.             return true;
  6.         }else if(elem.attachEvent){
  7.             var r = elem.attachEvent('on' + evType, func);
  8.             return r;
  9.         }else{
  10.             elem['on' + evType] = func;
  11.         }
  12.     },
  13.    
  14.     init: function(){
  15.         var infodiv = document.getElementById('info_libro');
  16.         var libro = document.getElementById('elLibro');
  17.         info.altura = infodiv.offsetHeight;
  18.         info.efecto();
  19.         info.addEvent(libro, 'click', info.efecto, false);
  20.     },
  21.    
  22.     efecto: function(){
  23.         if(info.abierto == false){
  24.             clearInterval(info.intervalo);
  25.             info.muestra();
  26.             info.abierto = true;
  27.         }else if(info.abierto == true){
  28.             clearInterval(info.intervalo);
  29.             info.oculta();
  30.             info.abierto = false;
  31.         }
  32.     },
  33.    
  34.     muestra: function(){
  35.         var infodiv = document.getElementById('info_libro');
  36.         infodiv.style.height = '0px';
  37.         infodiv.style.overflow = 'hidden';
  38.         info.intervalo = setInterval(function(){ info.redimenciona(info.altura); }, 1);
  39.     },
  40.    
  41.     oculta: function(){
  42.         var infodiv = document.getElementById('info_libro');
  43.         infodiv.style.height = infodiv.offsetHeight + 'px';// establesco la altura por que js no la lee a menos que haya sido establecida antes.
  44.         infodiv.style.overflow = 'hidden';
  45.         info.intervalo = setInterval(function(){ info.redimenciona(0); }, 1);
  46.     },
  47.    
  48.     redimenciona: function(limite){
  49.         var infodiv = document.getElementById('info_libro');
  50.         inicial = parseInt(infodiv.style.height);
  51.        
  52.         actual = Math.ceil((limite - inicial)/4);
  53.         inicial += actual;
  54.         infodiv.style.height = inicial + 'px';
  55.         if(parseInt(infodiv.style.height) >= (limite - 5) && parseInt(infodiv.style.height) <= (limite + 5)){
  56.             clearInterval(info.intervalo);
  57.             infodiv.style.height = limite + 'px';
  58.         }
  59.     },
  60.    
  61.     abierto: true
  62. }
  63.  
  64. info.addEvent(window, 'load', info.init, false);
Buenisimo Buzu, gracias por el codigo.

Lo estoy mirando y veo que tendria que modificar info_libro y elLibro, Perdon por la ignorancia pero no logro darme cuenta que serian y como tendría que declarar el texto oculto a partir de este nuevo javascript.

Gracias por tu ayuda.