@kizivat/svelte-autoscroll
v0.2.2
Published
Svelte action to automatically scroll to the end of an element.
Maintainers
Readme
Svelte Autoscroll Action
Svelte action to automatically scroll to the end of an element.
See demo at https://kizivat.eu/svelte-autoscroll/.
Simply used with the use directive.
<div use:autoscroll>...</div>The above div will automatically scroll to the end (bottom and right) when either
- It's children list or DOM subtree change or
- Any of the children change their size
Installation
npm i @kizivat/svelte-autoscrollUsage
Make sure the autoscroll element has overflow set to auto or scroll in at least one of the x or y directions.
<script>
import autoscroll from '@kizivat/svelte-autoscroll';
</script>
<div use:autoscroll>...</div>
<style>
div {
overflow: auto;
}
</style>Arguments
The action accepts an optional argument object. You can use it to
- modify the scroll behavior (
'smooth'or'auto', default:'smooth') - enable
pauseOnUserScrollfeature (default:false)
<!-- Modify default scroll behavior only -->
<div use:autoscroll={{ behavior: 'auto' }}>...</div>
<!-- Pause on user scroll -->
<div use:autoscroll={{ pauseOnUserScroll: true }}>...</div>
<!-- Both -->
<div use:autoscroll={{ pauseOnUserScroll: true, behavior: 'auto' }}>...</div>