'setTimeout to scrollIntoView in svelte
How would i run a bucle to scrollIntoView() in svelte with setTimeout().
I am trying to do an autoSlide.
const scrollIntoView = ({currentTarget}) => {
const scrollToElement = document.querySelector(
currentTarget.getAttribute('href')
)
if (!scrollToElement) return
scrollToElement.scrollIntoView({
behavior: 'smooth',
})
}
it is controlled by nav with on:click="{scrollIntoView}"
Solution 1:[1]
Add the preventDefault modifier:
<a href="#some_id" on:click|preventDefault={scrollIntoView}>...
In your current implementation the default is not prevented. (and by default the browser jumps to the targeted element instantly)
(Not sure what "run a bucle" means or why you'd want a setTimeout)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bob Fanger |
