11

Height transitions - Simple tabmenu para jugar con las transiciones

Publicado por Nikko el dia 11 Nov 2007 - Guardado en 99 Views Javascript, Scripts, Diseño Web 99 Views

simpletabmenu.jpg

Height transition es un efecto que cambia dinámicamente a la altura de un elemento. La mayoría de las veces esta transición se utilizan para ocultar o mostrar un elemento determinado en nuestra web. Mediante Height transition se utilizaran botones para activar la transición, y cuando se hace clic en un botón mostraremos el contenido determinado. Height transition nos permite además tener más de un elemento visualizado, ya que este no se vuelve a ocultar al abrir un nuevo elemento, sino que se oculta cuando nosotros lo hacemos también mediante los botones de acción.

Ver Demo - Descarga Ejemplo - Web solutoire

En nuestro encabezado

 

JavaScript:
  1. <script type="text/javascript" src="archivos/mootools.js"></script>
  2. <script type="text/javascript">
  3. window.onload = function(){
  4. //select the first button
  5. var button1 = $('button1');
  6. //select the second button
  7. var button2 = $('button2');
  8. //select the first content element
  9. var content1 = $('contentElement1');
  10. //select the second content element
  11. var content2 = $('contentElement2');
  12.  
  13. //The height transition we attach to 'contentElement1'
  14. var b1Toggle = new Fx.Style('contentElement1', 'height',{duration: 500});
  15. //The height transition we attach to 'contentElement2'
  16. var b2Toggle = new Fx.Style('contentElement2', 'height',{duration: 500});
  17.  
  18. //add an onclick event listener to button1
  19. button1.addEvent('click', function(){
  20.   //toggle height transition (hide-show)
  21.   if(content1.getStyle('height').toInt()> 0){
  22.     //hide
  23.   b1Toggle.start(0);
  24.   }else{
  25.     //show
  26.     b1Toggle.start(c1Height);
  27.   }
  28.   //toggle classname button1 <-> button1 button1_
  29.   button1.toggleClass('button1_');
  30.   return false;
  31. });
  32.  
  33. //add an onclick event listener to button2
  34. button2.addEvent('click', function(){
  35.   //toggle height transition (hide-show)
  36.   if(content2.getStyle('height').toInt()> 0){
  37.     //hide
  38.     b2Toggle.start(0);
  39.   }else{
  40.     //show
  41.     b2Toggle.start(c2Height);
  42.   }
  43.   //toggle classname button2 <-> button2 button2_
  44.   button2.toggleClass('button2_');
  45.   return false;
  46. });
  47.  
  48. //set css display:block for the contentElements
  49. content1.setStyle('display','block');
  50. content2.setStyle('display','block');
  51.  
  52. //get the scrollSize of the contentElements
  53. var c1Height = content1.getSize().scrollSize.y;
  54. var c2Height = content2.getSize().scrollSize.y;
  55. };
  56. </script>

Un poco de estilo CSS

CSS:
  1. #contentElement1,#contentElement2{
  2.     height:0px;
  3.     font-size:10px;
  4.     margin:0 auto;
  5.     overflow:hidden;
  6. }
  7. #contentWrapper{
  8.     margin:0px auto;
  9.     padding:5px 40px;
  10.     background:#d3e4a5;
  11.     overflow:hidden;
  12. }
  13. #button1, #button2{
  14.     display:block;
  15.     height:14px;
  16.     width:129px;
  17.     float:left;
  18.     margin-left:2px;
  19.     background:#d3e4a5;
  20.     cursor:pointer;
  21.     text-align:center
  22. }
  23. .button1_,.button2_{
  24.     font-weight:bold;
  25. }
  26. #button1{
  27.     margin-left:40px;
  28. }

Nuestro contenido

HTML:
  1. <div id="contentWrapper">
  2.     <div id="contentElement1">
  3.       <div align="left">Contenido Botón 1<br>
  4.         <br>
  5.         <img src="logo.jpg" align="left" />Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus rutrum elit et nunc. Phasellus tincidunt pede in nibh. Maecenas eget ligula non dui nonummy venenatis.
  6.  
  7. Aliquam tempor nibh. In vitae nulla a turpis elementum fermentum. Phasellus fermentum. Maecenas blandit enim in lorem sollicitudin pretium. Sed gravida diam non nibh. Phasellus imperdiet convallis nulla. Maecenas pulvinar molestie sem. Etiam aliquet volutpat felis. Nullam risus. Nullam eget elit non tortor mollis rhoncus. </div>
  8.   </div>
  9.     <div id="contentElement2">Contenido Botón 2<br>
  10.     <br>
  11. <img src="logo.jpg" align="left" />Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus rutrum elit et nunc. Phasellus tincidunt pede in nibh. Maecenas eget ligula non dui nonummy venenatis.
  12.  
  13. Aliquam tempor nibh. In vitae nulla a turpis elementum fermentum. Phasellus fermentum. Maecenas blandit enim in lorem sollicitudin pretium. Sed gravida diam non nibh. Phasellus imperdiet convallis nulla. Maecenas pulvinar molestie sem. Etiam aliquet volutpat felis. Nullam risus. Nullam eget elit non tortor mollis rhoncus. </div>
  14.  </div>
  15. </div>
  16. <div id="button1" class="button1">Botón 1 </div>
  17. <div id="button2" class="button2">Botón 2</div>

delicious, digg, barrapunto, meneame, digg , technorati , stumble it!
comentarios
  1. [...] Nick wrote an interesting post today!.Here’s a quick excerptcontent2.setStyle(’display’,’block’);. //get the scrollSize of the contentElements. var c1Height = content1.getSize().scrollSize.y;. var c2Height = content2.getSize().scrollSize.y;. };. . Un poco de estilo CSS. PLAIN TEXT. CSS: … [...]

  2. [...] Gino D. wrote an interesting post today!.Here’s a quick excerpt [...]

  3. fecazbldpr - Gravatar

    fecazbldpr

    11 - 11 - 2007

    Permalink

    Hello! Good Site! Thanks you! eudcmpoycareh

  4. [...] panel superior (arriba / abajo) con deslizamiento utilizando mootools, algo un poco similar a Height transitions que vimos hace meses. El resultado es muy agradable, o por lo menos a mi, me ha gustado mucho, es [...]

  5. [...] panel superior (arriba / abajo) con deslizamiento utilizando mootools, algo un poco similar a Height transitions que vimos hace meses. El resultado es muy agradable, o por lo menos a mi, me ha gustado mucho, es [...]

  6. Diezko - Gravatar

    Diezko

    11 - 11 - 2007

    Permalink

    hola. soy nuevo es esto del js y tengo una pregunta
    aparte del css el js y el html tengo q tener el archivo motools.js
    ya que veo que el js lo esta llamando --> src="archivos/mootools.js"

    de donde lo bajo?
    yo ya tengo uno de antes pero tiene el code que necesito?

    gracias.



Nombre: (Necesario)

E-mail: (Necesario)

Website:

Escribe tu comentario: