Create a two-page page that contains the main content and the sidebar.
I want to be able to smoothly scroll to the section tag with the same main content as the id in the href when I click on the sidebar link, but now I scroll to an unexpected place when I click the same link twice or after the second time.
No matter how many times you click on the same link, it stays in the same place, and when this occurs, we could infer that the value obtained by
destination.offset().top below is not the distance from the top of the parent element, but from the top of the browser screen.
I solved myself.
Obtain the current location of the element to scroll to, and then
By adding destination.offset().top to the destination element, the behavior was correct.
© 2022 OneMinuteCode. All rights reserved.