@kizivat/svelte-autoscroll
v0.2.2
Published
Svelte action to automatically scroll to the end of an element.
Downloads
190
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-autoscroll
Usage
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
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>