Accordion, scroll to top of active (open) accordion on click?

Hello!
I’m making accordions with a large amount of text. When you read to the bottom and click the next accordion, the large amount of text is collapsed and I’m left at the bottom of the page.

I’d like to scroll to top of the specific active panel that is open.

Please, it would be great not be left at the bottom of a page after closing an accordion with a large amount of text. Can anyone help me?

I found the code and used,I can scroll to top but cannot close the previous accordion.

SyntaxEditor Code Snippet

function SetEventMoveOpenItemToTop(){
  $( ""accordion-item-title"" ).click(function() {
      $('html').animate({scrollTop: $('.accordion-item is--open').offset().top-50}, 'fast');
   });
}



Thank you in advance!

Instead of trying to grab the 'accordion item is open', why not set an invisible div on top, give it a class on your own and scroll to there instead? Your function might run before the accordion changes, and then you'd be scrolling somewhere you didn't intend to