Use Lenis to use smooth scroll to anchors
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { addToCart } from '$utils/functions/shop'
|
||||
import { smoothScroll } from '$utils/functions'
|
||||
import { smoothScroll } from '$utils/stores'
|
||||
// Components
|
||||
import Button from '$components/atoms/Button.svelte'
|
||||
import Image from '$components/atoms/Image.svelte'
|
||||
@@ -16,7 +16,9 @@
|
||||
|
||||
<div class="poster">
|
||||
{#if image}
|
||||
<a href="/shop/poster-{location.slug}" on:click={() => smoothScroll({ hash: 'poster', changeHash: false })} data-sveltekit-noscroll data-sveltekit-prefetch>
|
||||
<a href="/shop/poster-{location.slug}" data-sveltekit-noscroll data-sveltekit-prefetch
|
||||
on:click={() => $smoothScroll.scrollTo('#poster', { duration: 2 })}
|
||||
>
|
||||
<Image
|
||||
id={image.id}
|
||||
sizeKey="product"
|
||||
@@ -35,7 +37,10 @@
|
||||
size="xsmall"
|
||||
url="/shop/poster-{location.slug}"
|
||||
text="View"
|
||||
on:click={() => setTimeout(() => smoothScroll({ hash: 'poster', changeHash: false }), 1000)}
|
||||
on:click={(event) => {
|
||||
event.preventDefault()
|
||||
setTimeout(() => $smoothScroll.scrollTo('#poster', { duration: 2 }), 1000)
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
tag="button"
|
||||
|
||||
@@ -26,9 +26,7 @@
|
||||
|
||||
// Scroll to anchor
|
||||
await tick()
|
||||
$smoothScroll.scrollTo(document.getElementById('poster').offsetTop, {
|
||||
duration: 2
|
||||
})
|
||||
$smoothScroll.scrollTo('#poster', { duration: 2 })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user