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

Overview

Scrollbox

Build Status Code Climate Bower version npm version Packagist Prerelease MIT licensed

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

Demo Page

Table of contents

Browser compatibility

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

... and others.

Scrollbox is automatically tested on the following browsers

Sauce Test Status

Installation

Several quick start options are available:

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

Usage

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

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

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

Then you should define max-height and/or max-width of that element:

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

and initialize Scrollbox:

$('#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.

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

Basic features

Options

Scrollbox uses several options to configuring behavior. The default options are:

{
    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.:

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

or re-define default values for all instances:

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

startAt.x

The initial position of the scroll on x-axis.

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

startAt.y

The initial position of the scroll on y-axis.

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

distanceToReach.x

The distance from the left and right boundaries of the content when reachleft.scrollbox and reachright.scrollbox events should be triggered.

This option is useful when you want to implement so-called "infinite scrolling".

distanceToReach.y

The distance from the top and bottom boundaries of the content when reachleft.scrollbox and reachright.scrollbox events should be triggered.

This option is useful when you want to implement so-called "infinite scrolling".

wheelSensitivity

The distance in pixels for one fixed step of mouse wheel.

You probably shouldn't change this value.

momentum.acceleration

Swipe acceleration factor.

momentum.thresholdTime

Threshold time in milliseconds for detect inertial moving at swipe.

templates

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

Methods

You can call some methods of the plugin.

.update()

Recalculates scrollbars' positions and sizes.

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:

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

.scrollBy(deltaX, deltaY, animationOptions)

Scrolls by pixels.

See .animate() for the available values of the animationOptions

Example:

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

If you want to scroll only on y-axis you can pass 0 as deltaX value:

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

.scrollTo(x, y, animationOptions)

Scrolls to specified position.

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

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

'left', 'right', 'top' and 'bottom' means the boundaries.

See .animate() for the available values of the animationOptions

Example:

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

If you want to scroll only on y-axis you can pass undefined as x value:

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

.destroy()

Completely removes all stuff from the element.

Events

Scrollbox triggers a several events during lifecycle.

reachleft.scrollbox

Triggered when scrolling reach the left boundary of the content. Respects distanceToReach.x option.

reachright.scrollbox

Triggered when scrolling reach the right boundary of the content. Respects distanceToReach.x option.

reachtop.scrollbox

Triggered when scrolling reach the top boundary of the content. Respects distanceToReach.y option.

reachbottom.scrollbox

Triggered when scrolling reach the bottom boundary of the content. Respects distanceToReach.y option.

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

You might also like...

jQuery Plugin For Delayed Event Execution

bindWithDelay jQuery plugin Author: Brian Grinstead MIT license: http://www.opensource.org/licenses/mit-license.php http://github.com/bgrins/bindWith

Dec 31, 2022

Renders and SVG schema of SARS-CoV-2 clade as defined by Neststrain

ncov-clade-schema https://ncov-clades-schema.vercel.app/ Visualizes current tree of SARS-CoV-2 clades. Allows to generate an SVG image of this tree. C

Nov 3, 2022

Sample AWS microservices app with service discovery defined using the CDK. Uses Docker + Fargate & ELB.

Sample AWS microservices app with service discovery defined using the CDK. Uses Docker + Fargate & ELB.

AWS Microservices Demo with CDK and Fargate About Simple AWS microservice-based app. Consists of two Spring Boot based services: Name Service GET /nam

Nov 23, 2022

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

OCPP-RPC A client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols (e.g. OCPP1.6J and OCPP2.0.1J). Re

Dec 30, 2022

CSS-based animations triggered by JS, defined in your stylesheet

Anim-x CSS-based animations triggered by JS, defined in your stylesheet. $ npm i https://github.com/LTBL-Studio/anim-x.git Quick start An animation is

Sep 29, 2021

Invadium runs exploit playbooks against vulnerable target applications in an intuitive, reproducible, and well-defined manner.

Invadium Invadium runs exploits against one or more target applications in an intuitive, reproducable, and well-defined manner. It focuses on bridging

Nov 6, 2022

Improve the security of your API by detecting common vulnerabilities as defined by OWASP and enforced with Spectral.

Spectral OWASP API Security Scan an OpenAPI document to detect security issues. As OpenAPI is only describing the surface level of the API it cannot s

Dec 8, 2022

Tampermonkey script which adds the ability to add a user-defined label/tag/flair on a user, shown throughout Hacker News.

Hacker News User Tags Hacker News User Tags is a Tampermonkey userscript which allows the user to associate a custom coloured label/tag on usernames t

Oct 7, 2022

A free and open-source point-of-sale (POS) system for retail and wholesale businesses with support for multiple branches, stockkeeping locations, POS profiles and price lists.

Note: This is a beta version of the software. You are advised to proceed with caution! Overview A free and open-source point-of-sale (POS) system for

Jan 27, 2022
Releases(v4.0.0)
A lightweight cross browser javascript scrollbar.

tinyscrollbar ** HELP MAINTAINER NEEDED!! ** Environments in which to use tinyscrollbar Browser support differs between the jQuery plugin and the plai

Maarten Baijs 398 Nov 9, 2022
A lightweight scrollbar library written in vanilla javascript.

A lightweight, dependency-free scrollbar library written in vanilla javascript. Fully customisable via CSS Native scrolling behaviour preserved Vertic

Karl 56 Dec 4, 2022
jQuery CSS Customizable Scrollbar

jQuery Scrollbar Cross-browser CSS customizable scrollbar with advanced features: Easy to implement No fixed height or width Responsive design support

Yuriy Khabarov 754 Jan 3, 2023
Calculates maximum composite SLA for a list of sequentially provided cloud services or your custom-defined services.

SlaMax Calculates maximum composite SLA for a list of sequentially provided cloud services or your custom-defined services. Here are a few use-cases y

Mikael Vesavuori 4 Sep 19, 2022
jQuery plugin to show a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML pages.

jquery.simpletabs v1.2.3 The jquery.simpletabs plugin shows a tabs bar for navigation. The tabs can be defined once, and shared across multiple HTML p

Peter Thoeny 1 Feb 23, 2022
Kuldeep 2 Jun 21, 2022
Add focal point alignment of images to your Alpine 3.x components with a custom directive.

Alpine Focal Add focal point alignment of images to your Alpine 3.x components with a custom directive. This package only supports Alpine v3.x. About

Michael Lefrancois 2 Oct 12, 2021
io-ts Typed Event Bus for the runtime of your Node.js application. A core for any event-driven architecture based app.

Typed Event Bus Based on io-ts types, this bus provides a handy interface to publish and consume events in the current runtime of the Node.js process.

Konstantin Knyazev 3 May 23, 2022
'event-driven' library aims to simplify building backends in an event driven style

'event-driven' library aims to simplify building backends in an event driven style(event driven architecture). For message broker, light weight Redis Stream is used and for event store, the well known NoSQL database, MongoDB, is used.

Sihoon Kim 11 Jan 4, 2023
🪆 Template intended to serve as a starting point if you want to bootstrap a Figma Plugin in TypeScript.

?? Codely Figma Plugin Skeleton Template intended to serve as a starting point if you want to bootstrap a Figma Plugin in TypeScript. Take a look, pla

CodelyTV 26 Dec 22, 2022