Dropdown Accordion With Anchored Content

I have a section with several dropdown accordions underneath (made according to this tutorial), each of the accordions has some content. The function is that when one accordion is opened, another (already open) is closed.
However, I can’t figure out how to display the contents of the accordion always at the top of the screen. I’ve tried to do this using element ID and an anchor, but the problem is that when the accordion is clicked, the page does move to the anchor first, but in the process the open accordion closes and the content of the newly opened accordion and the anchor move out of position. Thus, I am looking for a solution where the page only moves to the anchor when the previous accordion is closed. Do you have any experience with this please? Or is there another solution?

Here is my public share link: LINK
(how to access public share link)