Smooth scroll to anchor without a library
Custom function using scrollIntoView with smooth behavior
This commit is contained in:
@@ -179,6 +179,19 @@ export const parallaxAnime = (element, anime) => {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Smooth scroll to anchor on click
|
||||
*/
|
||||
export const smoothScroll = event => {
|
||||
const link = event.target.closest('a')
|
||||
const hash = link.getAttribute('href').split('#')[1]
|
||||
const target = document.getElementById(hash)
|
||||
target.scrollIntoView({ behavior: 'smooth' })
|
||||
history.pushState({}, null, `#${hash}`)
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Google Analytics send page
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user