0

I have a FAQ section with accordion for each questions.

When I open an question, I would like the window to scroll to the top of the title of the current opened accordion (instead of staying in the middle of the response).

I'm using this JS code :

<script>
jQuery(document).ready(function() {
  function close_accordion_section() {
    jQuery('.js-accordion-title').removeClass('active');
    jQuery('.js-accordion-panel').slideUp(300).removeClass('open');

  }
  jQuery('.js-accordion-title').click(function(e) {
    var currentAttrValue = jQuery(this).attr('href');
    if(jQuery(e.target).is('.active')) {
      close_accordion_section();
    }else {
      close_accordion_section();
      jQuery(this).addClass('active');
      jQuery('.js-accordion ' + currentAttrValue).slideDown(300).addClass('open'); 
    }
    e.preventDefault();
  });
});
</script>

Does someone has an idea ?.. Thanks in advance for your help :)

0

Browse other questions tagged or ask your own question.