My aim is to create a smooth scrolling anchor link menu using Nuxt.js, where the user can click on a link and be directed to the corresponding page section. However, I'm facing a dilemma as there are multiple approaches to achieve this functionality, and I'm unsure which one is the most suitable.
Option 1:
In my first attempt, I implemented a menu that calculates the offsetTop
of each section div to determine the scroll distance when a user clicks on a menu link. The issue with this method is that certain values of the divs, such as offsetHeight
and offsetTop
, tend to change when the project is deployed to the server. Consequently, the links end up scrolling to incorrect positions and do not function correctly.
I experimented with swapping the order of the 'Value' and 'Problem' sections, which temporarily resolved the problem. However, the correct sequence of sections needed to be maintained.
In this approach, I utilize the created() lifecycle hook to retrieve these values and store them in Vuex state. These values are then accessed in another component where the menu functionality resides:
.................................... (The rest of the original content remains unchanged) ..........................Now, I find myself torn between these two options, unsure of where to invest my time and effort for the best outcome.