Smooth scroll for anchor link

This commit is contained in:
2020-02-17 22:39:50 +01:00
parent f1af0806f1
commit 2ae935aca5
2 changed files with 15 additions and 1 deletions

View File

@@ -39,6 +39,20 @@ export const isInViewport = element => {
}
/*
** Smooth Scroll
*/
export const smoothScroll = (event, element = null) => {
document.querySelector(element).scrollIntoView({
behavior: 'smooth',
block: 'start'
})
event.preventDefault()
}
/*
** Random String Generator
*/

View File

@@ -99,7 +99,7 @@
<div class="intro__description style-description">
<p>{$site.description}</p>
<Button href="#choose" type="a" className="button" text="Explore locations">
<Button type="a" href="#choose" className="button" text="Explore locations" on:click={e => fn.smoothScroll(e, '#choose')}>
<IconGlobeSmall width="22" color="#666" />
</Button>
</div>