I am curious how I can scroll the target id element of an anchor tag's href to the center of the page using the scrollIntoView method.
Here is my code so far:
$("a").click(function () {
var target = $($(this).attr("href"));
target[0].scrollIntoView({
behavior: "smooth",
block: "center"
})
});
I am able to log the targeted element to the console and use other methods to change the targeted element but can't figure out how to center it when scrolling.
Here is a Codepen with an example of what I'd like to do but instead uses scroll-margin-top: 50vh.
Anything is appreciated, Thx.