Git Product home page Git Product logo

react-touch-drag-slider's Introduction

react-touch-drag-slider

Touch and drag slider carousel component for React

Slider Gif

  • Touch friendly on mobile
  • Responsive to viewport resizing
  • Supports mouse drag by default
  • Simple API
  • Sizes to any size parent container
  • small bundle size with zero dependencies

Install

npm i react-touch-drag-slider

Usage

import React from 'react'
import Slider from 'react-touch-drag-slider'

// here we are importing some images
// but the Slider children can be an array of any element nodes,
// or your own components

import images from './images'

function App() {
  return (
    <Slider
      onSlideComplete={(i) => {
        console.log('finished dragging, current slide is', i)
      }}
      onSlideStart={(i) => {
        console.log('started dragging on slide', i)
      }}
      activeIndex={0}
      threshHold={100}
      transition={0.5}
      scaleOnDrag={true}
    >
      {images.map(({ url, title }, index) => (
        <img src={url} key={index} alt={title} />
      ))}
    </Slider>
  )
}

export default App

Available Props

Prop Type Default Description
onSlideComplete (completedIndex: number) => void A function that gets called when finished
onSlideStart (startIndex: number) => void A function that gets called on start
activeIndex number 0 Set to start on this index or use state to update the current index
threshHold number 100 A pixel value that must be dragged before slide snaps to position
transition number 0.3 The transition delay in seconds
scaleOnDrag boolean false Should the individual slide scale while dragging

Examples

Most basic example with no props - CodeSandBox link

With props, local state and buttons (you provide the buttons) - CodeSandbox link

For example of use in a full screen modal with a gallery, please checkout any of the galleries in Bushblade Knives

License

MIT © bushblade

react-touch-drag-slider's People

Contributors

bushblade avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-touch-drag-slider's Issues

How to override padding between `Slider` elements?

Hiyah,
Screen Shot 2022-07-21 at 2 13 05 AM
Screen Shot 2022-07-21 at 2 12 45 AM

I want to get rid of padding between elements and I noticed that its div is randomly generated on re-renders so its hard to systematically determine where to override. I've already tried a global div, adding styles to Slider directly, and (in vain) tried on individual elements. So far this has been the best carousel package I've tried, so it'd be great to know how to customize :)

Failed to compile. issue

Hello author,
I found this when using the slider, would you please help to advise what to do? thanks a lot!
./node_modules/react-touch-drag-slider/dist/lib.es.js 714:10
Module parse failed: Unexpected token (714:10)
You may need an appropriate loader to handle this file type

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.