Fix Shop location switcher scroll when changing
This commit is contained in:
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { getContext } from 'svelte'
|
import { getContext, tick } from 'svelte'
|
||||||
import { shopCurrentProductSlug } from '$utils/stores/shop'
|
import { shopCurrentProductSlug } from '$utils/stores/shop'
|
||||||
import { smoothScroll } from '$utils/functions'
|
import { smoothScroll } from '$utils/stores'
|
||||||
|
|
||||||
export let isOver: boolean = false
|
export let isOver: boolean = false
|
||||||
|
|
||||||
const { shopLocations } = getContext('shop')
|
const { shopLocations }: any = getContext('shop')
|
||||||
|
|
||||||
const classes = [
|
const classes = [
|
||||||
'shop-locationswitcher',
|
'shop-locationswitcher',
|
||||||
@@ -20,11 +20,15 @@
|
|||||||
|
|
||||||
|
|
||||||
// Quick location change
|
// Quick location change
|
||||||
const quickLocationChange = ({ target: { value }}: any) => {
|
const quickLocationChange = async ({ target: { value }}: any) => {
|
||||||
const newPath = `/shop/poster-${value}`
|
const pathTo = `/shop/poster-${value}`
|
||||||
goto(newPath, { replaceState: true, noscroll: true, keepfocus: true })
|
goto(pathTo, { replaceState: true, noscroll: true, keepfocus: true })
|
||||||
|
|
||||||
// Scroll to anchor
|
// Scroll to anchor
|
||||||
setTimeout(() => smoothScroll({ hash: 'poster' }), 1000)
|
await tick()
|
||||||
|
$smoothScroll.scrollTo(document.getElementById('poster').offsetTop, {
|
||||||
|
duration: 2
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user