Skip to content

Commit

Permalink
feat: Carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed May 26, 2024
1 parent bce61ad commit d3f9e37
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/runtime/helpers/dedicated/Carousel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script>
import { url } from '../index.js'
import { RouteOnScroll } from './RouteOnScroll/index.js'
/** @type {ConstructorParameters<typeof RouteOnScroll>['0']}*/
export let options = { direction: 'horizontal' }
// const routeOnScroll = new RouteOnScroll($url, {
const routeOnScroll = new RouteOnScroll({
scrollEvent: 'scroll', // or "scrollend"
threshold: 100, // don't trigger until we're within 100px of the page
direction: 'horizontal',
strategy: 'withinThreshold',
...options,
})
</script>

<div
class={$$props.class}
data-routify-carousel={routeOnScroll.direction}
data-routify-scroll-lock
use:$routeOnScroll>
<slot />
</div>

<style>
/**
* Scroll snap
*/
[data-routify-carousel] {
display: grid;
overflow: auto;
scroll-behavior: smooth;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
}
[data-routify-carousel] > :global(*) {
scroll-snap-align: start;
}
[data-routify-carousel='horizontal'] {
grid-auto-flow: column;
grid-auto-columns: 100%;
scroll-snap-type: x mandatory;
}
[data-routify-carousel='vertical'] {
grid-auto-flow: row;
grid-auto-rows: 100%;
scroll-snap-type: y mandatory;
}
</style>

0 comments on commit d3f9e37

Please sign in to comment.