Exciting release!Introducing "safe npm". Learn more
Socket
Log inDemoInstall

react-touch-drag-slider

Package Overview
Dependencies
2
Maintainers
1
Versions
21
Issues
File Explorer

Advanced tools

react-touch-drag-slider

Touch and drag slider carousel component for React

    2.2.5latest
    GitHub

Version published
Maintainers
1
Weekly downloads
854
increased by30.78%

Weekly downloads

Readme

Source

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

PropTypeDefaultDescription
onSlideComplete(completedIndex: number) => voidA function that gets called when finished
onSlideStart(startIndex: number) => voidA function that gets called on start
activeIndexnumber0Set to start on this index or use state to update the current index
threshHoldnumber100A pixel value that must be dragged before slide snaps to position
transitionnumber0.3The transition delay in seconds
scaleOnDragbooleanfalseShould 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

Keywords

FAQs

Last updated on 03 Oct 2022

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • 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