Socket
Socket
Sign inDemoInstall

swipe-scroller

Package Overview
Dependencies
21
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    swipe-scroller

Horizontal card slider for the modern web


Version published
Weekly downloads
12
increased by50%
Maintainers
1
Install size
12.9 kB
Created
Weekly downloads
 

Readme

Source

Swipe Scroller for Svelte

Horizontal card slider for the modern web. Requires minimum JavaScript. Demo

Features

  • Performant - scrolling and snapping are powered by CSS, not JS.
  • Accessible - control with touch, scroll, click1, and keyboard2.
  • Customizable - override the provided buttons and the <noscript>.

Browser Support

Tested on the latest evergreen browsers.

ChromeSafariFirefoxSafari (iOS)Samsung Internet
CSS Scroll Snap6911681110.1
CSS Scroll-behavior6115.43615.48.2

Quick Start

npm create svelte@latest
npm i swipe-scroller -D

Following code is based on SvelteKit v1.

<!-- src/routes/+layout.svelte -->

<script>
  import 'swipe-scroller/style';
</script>

<div class="container-outer" style="position: fixed; inset: 0;" />

<div style="position: relative; overflow-x: hidden;">
  <slot />
</div>
<!-- src/routes/+page.svelte -->

<script>
  import Scroller from 'swipe-scroller/Scroller.svelte';
</script>

<div class="container-inner">
  <h1>Swipe Scroller</h1>
</div>

<Scroller>
  {#each { length: 5 } as _, index}
    <a href="#{index}" class="card">
      <img src="https://scroller.hyunbin.page/{index}.jpg" alt="" />
      <div>Card No. {index + 1}</div>
    </a>
  {/each}
</Scroller>

<style>
  .card {
    text-decoration: none;
    color: white;
    background-color: gray;
    width: 80%;
    min-width: 224px;
    max-width: 296px;
    overflow: hidden;
  }

  .card > img {
    display: block;
    aspect-ratio: 1;
    width: 100%;
  }

  .card > div {
    padding: 1rem;
    text-align: center;
  }
</style>

Reference how it works for an in-depth explanation.

Events

The following DOM events are forwarded to the component.

<!-- Provide custom callbacks if needed. -->
<Scroller on:scroll on:scrollend />

Options

// Optional Component Props

/** Width and height of the clickable control buttons. */
export let buttonWidth = '2.5rem';
/** Horizontal gap between the provided card components. */
export let cardGap = '1.25rem';

/** Hang control buttons on the outer container border. */
export let hangButtons = true;
/** Invert the scroll direction of the control buttons. */
export let invertButtons = false;

Slots

<!-- Optional Named Slots -->

<slot name="noscript" />
<slot name="button-prev" />
<slot name="button-next" />

Limitations

  • JavaScript is required to enable horizontal scroll.
  • Card components should have identical width.

Footnotes

  1. The buttons are shown only when hovered with @media (pointer: fine) such as a mouse cursor.

  2. For accessibility, wrap the card component with tabbable elements such as <a> or <button>.

FAQs

Last updated on 28 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc