Wow, quite messy but it did fix the menu closing issue. There is another issue though - because my navbar is sticky, when it scrolls to the section, the top part of that section is cut off (it gets more cut off the smaller the viewport is).
I changed it to 'fixed' and added an empty div to give the hero some space. This works except when navigating to that section from the other pages (top part gets cut off again).
Any ideas?