Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scrollbooster

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scrollbooster

Enjoyable content drag-to-scroll library

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
increased by1.99%
Maintainers
1
Weekly downloads
 
Created
Source

ScrollBooster

Enjoyable content drag-to-scroll micro (~2KB gzipped) library.

Installation

You can install it via npm package manager or just drop a script tag:

npm i scrollbooster
<script src="https://unpkg.com/scrollbooster@1.0.4/dist/scrollbooster.min.js"></script>

Usage

import ScrollBooster from 'scrollbooster'

let sb = new ScrollBooster({
  viewport: document.querySelector('.viewport') // required
  // ...other options
})

Options

OptionTypeDefaultDescription
viewportelementnullViewport - outer element
contentelementFirst child of viewport elementScrollable content inside viewport
handleelementViewport elementElement that respond to drag event
bouncebooleantrueInertia bounce effect (scroll past viewport borders)
textSelectionbooleanfalseAbility to select text content
frictionfloat0.05Scroll friction factor (scroll inertia after pointer release)
bounceForcefloat0.1Bounce effect factor
emulateScrollbooleanfalseEmulate viewport mouse wheel events (for cases when scrolling with transform property)
onUpdatefunctionnoopUser function that updates element properties according to received coordinates (see demo examples). Receives object with properties: position, viewport and content. Each property contains metrics to perform an actual scrolling

Methods

MethodDescription
setPositionSets new scroll position in viewport. Receives an object with properties x and y
updateMetricsUpdates element sizes. Useful for images loading or other dynamic content
getUpdateReturns current metrics and coordinates in a same format as onUpdate
destroyDestroys all instance's event listeners

Full Example

let viewport = document.querySelector('.viewport')
let content = document.querySelector('.viewport-content')

let sb = new ScrollBooster({
  viewport: viewport,
  content: content,
  handle: document.querySelector('.viewport-scroller'), 
  bounce: true,
  textSelection: false,
  emulateScroll: false,
  onUpdate: (data)=> {
    content.style.transform = `translate(
      ${-data.position.x}px,
      ${-data.position.y}px
    )`
    // and also metrics: data.viewport['width'|'height'] and data.cotent['width'|'height']
  }
})

// methods example:
sb.updateMetrics()
sb.setPosition({
  x: 100,
  y: 100
})
sb.destroy()

Browser support

ScrollBooster has been tested in IE 11, Edge and other modern browsers (Chrome, Firefox, Safari).

Special thanks

David DeSandro for his talk "Practical UI Physics".

License

MIT License (c) Ilya Shubin

Keywords

FAQs

Package last updated on 24 Mar 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc