Code Monkey home page Code Monkey logo

virtual-scroll's Introduction

virtual-scroll

Custom scroll event with inertia/momentum, touch (works on <=iOS7) and keyboard compatible. This is a fork of Bartek Drozdz VirtualScroll util. See his article) for a complete description.

Goals of the fork

  • Easier to add in a CommonJS / require environment
  • Enable to create several distinct instances by using a prototype rather than a singleton
  • Add some extra features
  • modules (using a dedicated Emitter for instance)

Installation

npm i virtual-scroll -S

Usage & API

For in-depth usage and tutorial, you can check Bartek's article (link above).

  • new VirtualScroll(options) Return a new instance of VirtualScroll. See the options below.

  • instance.on(fn, context) Listen to the scroll event using the specified function (fn) and optional context.

  • instance.off(fn, context) Remove the listener.

  • instance.destroy() Will remove all events and unbind the DOM listeners.

Events note: Each instance will listen only once to any DOM listener. These listener are enabled/disabled automatically. However, it's a good practice to always call destroy() on your VirtualScroll instance, especially if you are working with a SPA.

Options

  • mouseMultiplier: General multiplier for all mousewheel (including Firefox). Default to 1.
  • touchMultiplier: Mutiply the touch action by two making the scroll a bit faster than finger movement. Default is 2.
  • firefoxMultiplier: Firefox on Windows needs a boost, since scrolling is very slow. Default is 15.
  • keyStep: How many pixels to move with each key press. Default is 120.
  • preventTouch: If true, automatically call e.preventDefault on touchMove. Default is false.
  • unpreventTouchClass: Elements with this class won't preventDefault on touchMove. For instance, useful for a scrolling text inside a VirtualScroll-controled element. Default is vs-touchmove-allowed.
  • limitInertia: if true, will leverage Lethargy to avoid everlasting scroll events (mostly on Apple Mouse, Trackpad, and free-wheel mouse). Default is false.

Todo

  • In-depth tests
  • Possibility to pass a 'keys' options (bind other keyboard keys)
  • Add a "direction" option to force a single direction?

virtual-scroll's People

Contributors

ayamflow avatar baptistebriel avatar jackismissing avatar

Watchers

 avatar  avatar

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.