A Svelte action and attachment for adding beautiful fade effects to overflowing content
npm install svelte-overflow-fade
pnpm add svelte-overflow-fade
yarn add svelte-overflow-fade
<script>
import { overflowFadeAction } from 'svelte-overflow-fade';
</script>
<div
class="overflow-auto max-h-64"
use:overflowFadeAction={{
axis: 'y',
fade: { type: 'mask', fadePercent: 10 }
}}
>
<!-- Your scrollable content -->
</div>
<script>
import { overflowFade } from 'svelte-overflow-fade';
</script>
<div
class="overflow-auto max-h-64"
{@attach overflowFade({
axis: 'y',
fade: { type: 'mask', fadePercent: 10 }
})}
>
<!-- Your scrollable content -->
</div>
Option | Type | Description |
---|---|---|
axis |
'x' | 'y' |
Direction of scroll (horizontal or vertical) |
fade.type |
'mask' | 'element' |
Fade implementation method |
fade.fadePercent |
number |
Size of fade as percentage (mask mode only) |
fade.size |
string |
Size of fade in CSS units (element mode only) |
fade.backgroundColor |
string |
Fade color (element mode only) |
fade.zIndex |
number |
Z-index for fade elements (element mode only) |
mask-image
for smooth, native fadingfade: {
type: 'mask',
fadePercent: 10
}
fade: {
type: 'element',
size: '60px',
backgroundColor: 'white',
zIndex: 10
}
The action dispatches an overflow
event with the current overflow state:
<script>
function handleOverflow(event) {
const { overflowTop, overflowBottom, overflowLeft, overflowRight } = event.detail;
// React to overflow changes
}
</script>
<div use:overflowFadeAction={{ axis: 'y' }} on:overflow={handleOverflow}>
<!-- Content -->
</div>
MIT © Harsh Mandan