My goal is to easily scroll to a specific element using #
:
<a href="#element">Element</a>
<div name="element" />
While this method works effectively, it always takes me to the top of the element. I would prefer to have the element centered on the screen for the user.
I am a bit hesitant to rely on Javascript's scrollTo
or other external libraries, as I will need this feature frequently. Since I am using React, I want to avoid overusing refs
and slowing down my application. Ideally, I would like to achieve this using just HTML, but I'm open to using JavaScript as well. However, most of the solutions I have found involve modifying the DOM and/or using refs
.