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
npm i @kizivat/svelte-autoscroll
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>
The action accepts an optional argument object. You can use it to
'smooth' or 'auto', default: 'smooth')pauseOnUserScroll feature (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>