Change location.hash *before* scrolling.

You have to update `location.hash` before scrolling or the browser history will break and not jump to the correct positions in the document.