Desplácese a un elemento después de un clic con deslizamiento hacia abajo en jQuery

StackOverflow https://stackoverflow.com/questions/7801959

  •  22-10-2019
  •  | 
  •  

Pregunta

Estaba buscando cómo desplazarme en el siguiente elemento como este:

http://www.grittirollo.it/

Haga clic en esas letras grandes y se desplaza al elemento actual después de hacer clic y deslizar el efecto hacia abajo.

Ahí está mi intento: (jsfiddle: http://jsfiddle.net/d272p/)

Html

<div id="head1">Click</div>
<div id="child1">Content</div>

<br/>

<div id="head2">Click</div>
<div id="child2">Content</div>

<br/>

<div id="head3">Click</div>
<div id="child3">Content</div>

CSS

#head1{width: 400px; height: 40px; background: orange;}
#head2{width: 400px; height: 40px; background: red;}
#head3{width: 400px; height: 40px; background: purple;}

#child1{width: 300px; height: 700px; background: green; display: none;}
#child2{width: 300px; height: 700px; background: cyan; display: none;}
#child3{width: 300px; height: 700px; background: pink; display: none;}

Javascript

$('#head1').click(function() {
  $('#child1').animate({
    opacity: 'toggle',
    height: 'toggle'
  },
  {
    duration: 750,
    specialEasing: {
      width: 'linear',
      height: 'easeInOutQuad'
    },
  }
  );
});

$('#head2').click(function() {
  $('#child2').animate({
    opacity: 'toggle',
    height: 'toggle'
  },
  {
    duration: 750,
    specialEasing: {
      width: 'linear',
      height: 'easeInOutQuad'
    },
  }
  );
});

$('#head3').click(function() {
  $('#child3').animate({
    opacity: 'toggle',
    height: 'toggle'
  },
  {
    duration: 750,
    specialEasing: {
      width: 'linear',
      height: 'easeInOutQuad'
    },
  }
  );
});
¿Fue útil?

Solución

JQuery scrollto Debería hacer el truco

Editar

Después de revisar el sitio de muestra, me doy cuenta de que JQuery ui accordian podría ser la mejor opción.

Otros consejos

Esta funcionalidad se puede lograr usando JQuery Accordion

Verifique el enlace http://jqueryui.com/demos/accordion/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top