1.0.4 • Published 3 years ago

dragscroll-ts v1.0.4

Weekly downloads
11
License
MIT
Repository
github
Last release
3 years ago

🎉 DragScroll library

Drag Scroll library - smooth content scroll via mouse/touch dragging. Publish standard format Js such as commonJs, ES Modules, UMD, Typescript

Alt text

Why DragScroll ?

  • More comfortable with physical UI, make consistency between different devices

Usage

First of all, you need to import this library:

// Javascript tag
<script type="type/javascript" src="https://unpkg.com/dragscroll-ts@1.0.2/build/dragscroll.min.js"></script>
// Common Javascript
const DragScroll = require('dragscroll-ts')
// ES6 Module Javascript
import DragScroll from 'dragscroll-ts'
// Typescript
import DragScroll, { IDragScrollOptions } from 'dragscroll-ts'

const options: IDragScrollOptions = {}

interface IDragScrollOptions {
    $container: HTMLElement
    $content: HTMLElement
    axis: string
    allowInputFocus?: boolean
    allowSelectText?: boolean
}

Next step, init drag scroll instance

- NOTE: This library only wrap dragscroll logic on available HTML, It doesn't touch to stylesheet 😉
- Need to be specified the HTML structure of $container, $content elements. See picture below
const $container = document.getElementById('demo-wrapper')
const $content = document.getElementById('demo-content')

new DragScroll({
    $container: $container,
    $content: $content,
    axix: 'x',
    allowInputFocus: true,
    allowSelectText: false,
})

Alt text

Config options

OptionTypeDescription
\$containerHTMLElementThe element wrap the dragable element
\$contentHTMLElementThe dragable child element of \$container.
axisstringDefault is 'x'. There are 3 values: 'x', 'y','xy'
'x' is horizontal direction
'y' is vertical direction
'xy' is both direction
allowInputFocusbooleanAllow input fields can be focused
allowSelectTextbooleanAllow text content can be selected

API

NameDescription
scrollToPass coordinate object { x, y } to scroll to target position
setInputCanBeFocusedDefault is true. Input fields can be focused
setTextCanBeSelectedDefault is true. Text content can be selected
destroyRemove all listeners

Events

The evt parameter is either MouseEvent or TouchEvent

NameDescription
dragstartTo be fired when starting drag
draggingTo be fired when dragging
dragendTo be fired when dragging content meet end point
// Example:
const dragSroll = new DragScroll({})
function handler(evt) {}

dragSroll.on('dragstart', handler)
dragSroll.off('dragstart', handler)

Files size

FileFormatsize
dragscroll.min.jsUMD7.6 KB
dragscroll.cjs.jsCommon Js6.96 KB
dragscroll.es.jsES Module6.95 KB

License

MIT License (c) 2020 XuanVinh