2017 © Pedro Peláez
 

component scrollbox

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

image

invis1ble/scrollbox

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  • Sunday, January 22, 2017
  • by Invis1ble
  • Repository
  • 3 Watchers
  • 12 Stars
  • 19 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 30 Versions
  • 0 % Grown

The README.md

Scrollbox

Build Status Code Climate Bower version npm version Packagist Prerelease MIT licensed, (*1)

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point., (*2)

Demo Page, (*3)

Table of contents

Browser compatibility

  • IE 7+
  • Firefox
  • Opera (old and new)
  • Safari
  • Chrome
  • Chrome for Android

... and others., (*4)

Scrollbox is automatically tested on the following browsers, (*5)

Sauce Test Status, (*6)

Installation

Several quick start options are available:, (*7)

  • Download the latest release.
  • Clone the repo: git clone https://github.com/Invis1ble/scrollbox.git.
  • Install with Bower: bower install scrollbox.
  • Install with npm: npm install scrollbox.
  • Install with Composer: composer require invis1ble/scrollbox.

After installing the plugin you have to install jquery-mousewheel. You can simply download it as archive and unpack to desired location., (*8)

Usage

In order to use the plugin, you have to include styles and script to your html e.g.:, (*9)

<link href="/path/to/scrollbox.min.css" media="screen" rel="stylesheet" type="text/css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/path/to/jquery.mousewheel.min.js" type="text/javascript"></script>
<script src="/path/to/scrollbox.min.js" type="text/javascript"></script>

Let's assume that you want to stylize the following element:, (*10)

<div id="long-content-container">
    Here is a long content
</div>

Then you should define max-height and/or max-width of that element:, (*11)

#long-content-container {
    max-height: 200px;
    max-width: 200px;
}

and initialize Scrollbox:, (*12)

$('#long-content-container').scrollbox();

That's all. Now if real size of the container is greater than the specified max-height/max-width then the plugin will add scrollbar to it., (*13)

You can stylize scrollbar via css or even better by overwriting corresponding less variables. See src/less/ for more details., (*14)

Basic features

Options

Scrollbox uses several options to configuring behavior. The default options are:, (*15)

{
    distanceToReach: {
        x: 0,
        y: 0
    },
    wheelSensitivity: 20,
    momentum: {
        acceleration: 1600,
        thresholdTime: 500
    },
    startAt: {
        x: 'left',
        y: 'top'
    },
    templates: {
        horizontalBar: '<div></div>',
        verticalBar: '<div></div>',
        horizontalRail: '<div></div>',
        verticalRail: '<div></div>',
        wrapper: '<div></div>'
    }
}

You can optionally pass an object containing all of the options that you would like to initialize Scrollbox with e.g.:, (*16)

$('#long-content-container').scrollbox({
    wheelSensitivity: 25,
    startAt: {
        y: 'bottom'
    }
});

or re-define default values for all instances:, (*17)

$.fn.scrollbox.Constructor.getDefault().distanceToReach.y = 100;

startAt.x

The initial position of the scroll on x-axis., (*18)

The value can be 'left', 'right' or number of pixels from the left boundary., (*19)

startAt.y

The initial position of the scroll on y-axis., (*20)

The value can be 'top', 'bottom' or number of pixels from the top boundary., (*21)

distanceToReach.x

The distance from the left and right boundaries of the content when reachleft.scrollbox and reachright.scrollbox events should be triggered., (*22)

This option is useful when you want to implement so-called "infinite scrolling"., (*23)

distanceToReach.y

The distance from the top and bottom boundaries of the content when reachleft.scrollbox and reachright.scrollbox events should be triggered., (*24)

This option is useful when you want to implement so-called "infinite scrolling"., (*25)

wheelSensitivity

The distance in pixels for one fixed step of mouse wheel., (*26)

You probably shouldn't change this value., (*27)

momentum.acceleration

Swipe acceleration factor., (*28)

momentum.thresholdTime

Threshold time in milliseconds for detect inertial moving at swipe., (*29)

templates

Normally you don't need to change this templates, but you can if you want., (*30)

Methods

You can call some methods of the plugin., (*31)

.update()

Recalculates scrollbars' positions and sizes., (*32)

For example, If you write the infinite scroll implementation you have to update scrollbar position and size after content has been added. To do this you should simply call .update() method:, (*33)

$('#long-content-container').scrollbox('update');

.scrollBy(deltaX, deltaY, animationOptions)

Scrolls by pixels., (*34)

See .animate() for the available values of the animationOptions, (*35)

Example:, (*36)

$('#long-content-container').scrollbox('scrollBy', 100, 200);

If you want to scroll only on y-axis you can pass 0 as deltaX value:, (*37)

$('#long-content-container').scrollbox('scrollBy', 0, 200);

.scrollTo(x, y, animationOptions)

Scrolls to specified position., (*38)

x can be integer (pixels), or string 'left' or 'right'., (*39)

y also can be integer (pixels), or string 'top' or 'bottom'., (*40)

'left', 'right', 'top' and 'bottom' means the boundaries., (*41)

See .animate() for the available values of the animationOptions, (*42)

Example:, (*43)

$('#long-content-container').scrollbox('scrollTo', 100, 200);

If you want to scroll only on y-axis you can pass undefined as x value:, (*44)

$('#long-content-container').scrollbox('scrollTo', undefined, 'bottom');

.destroy()

Completely removes all stuff from the element., (*45)

Events

Scrollbox triggers a several events during lifecycle., (*46)

reachleft.scrollbox

Triggered when scrolling reach the left boundary of the content. Respects distanceToReach.x option., (*47)

reachright.scrollbox

Triggered when scrolling reach the right boundary of the content. Respects distanceToReach.x option., (*48)

reachtop.scrollbox

Triggered when scrolling reach the top boundary of the content. Respects distanceToReach.y option., (*49)

reachbottom.scrollbox

Triggered when scrolling reach the bottom boundary of the content. Respects distanceToReach.y option., (*50)

Infinite scrolling implementation example

var $container = $('#content-container');

$container
    .on('reachbottom.scrollbox', function () {
        $.ajax({
            // options
        }).done(function (response) {
            $container
                .append(response)
                .scrollbox('update');
        });
    })
    .scrollbox({
        distanceToReach: {
            y: 100
        }
    });

License

The MIT License, (*51)

The Versions

22/01 2017

dev-master

9999999-dev

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

22/01 2017

4.0.0

4.0.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

22/01 2017

dev-develop

dev-develop

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

09/10 2016

3.0.1

3.0.1.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

09/10 2016

3.0.0

3.0.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

08/10 2016

3.0.0-rc.0

3.0.0.0-RC0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

07/10 2016

3.0.0-beta.4

3.0.0.0-beta4

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

07/10 2016

3.0.0-beta.3

3.0.0.0-beta3

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

07/10 2016

3.0.0-beta.2

3.0.0.0-beta2

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

06/10 2016

3.0.0-beta.1

3.0.0.0-beta1

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

05/10 2016

3.0.0-beta

3.0.0.0-beta

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

03/10 2016

3.0.0-alpha.1

3.0.0.0-alpha1

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

01/10 2016

3.0.0-alpha

3.0.0.0-alpha

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

06/06 2016

2.4.0

2.4.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

03/06 2016

2.3.1

2.3.1.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrolling scrollbar kinetic touchscreen infinite-scrolling momentum inertia

01/06 2016

2.3.0

2.3.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

01/06 2016

2.2.2

2.2.2.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

01/06 2016

2.2.0

2.2.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

03/04 2016

2.1.6

2.1.6.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

01/04 2016

2.1.5

2.1.5.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

01/04 2016

2.1.4

2.1.4.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

01/04 2016

2.1.3

2.1.3.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

01/04 2016

2.1.2

2.1.2.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

31/03 2016

2.1.1

2.1.1.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

31/03 2016

2.1.0

2.1.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

31/03 2016

2.0.0

2.0.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

30/03 2016

1.0.0

1.0.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar touchscreen

15/08 2014

0.3.1

0.3.1.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar

12/08 2014

0.3.0

0.3.0.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar

11/08 2014

0.2.2

0.2.2.0

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

  Sources   Download

MIT

by Avatar Invis1ble

jquery ui trigger scroll scrollbar