Code Monkey home page Code Monkey logo

swipe-scroller's Introduction

Swipe Scroller for Svelte

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

Features

  • Snapping Cards, Smooth Scroll - Powered by CSS, not JS.
  • Easy to Use - Just pass the card components to the <slot />.
  • Customizable - Override the provided buttons and <noscript>.
  • Various Controls - Supports touch, scroll, click1, and the tab key2.
  • Light or Dark - The semi-transparent clickable buttons suits both.

Requirements

Supported and tested on the latest evergreen browsers.

Chrome Safari Firefox Safari (iOS) Samsung Internet
CSS Scroll Snap 69 11 68 11 10.1
CSS Scroll-behavior 61 15.4 36 15.4 8.2

Limitations

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

Installation

Reference How it works for in-depth explanation.

  1. Prepare a SvelteKit project3.
  2. Install the package via npm.
  3. Reference the src/routes directory4.

For new projects, replace the content of the src/routes folder. Download

Events

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" />

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>.

  3. The project should support both +(layout|page).svelte files. SvelteKit 1.x is recommended.

  4. The directory contains the source code for the demo page. It can be used as a starter template.

swipe-scroller's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.