A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.
A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point., (*2)
Demo Page, (*3)
... and others., (*4)
Scrollbox is automatically tested on the following browsers, (*5)
Several quick start options are available:, (*7)
git clone https://github.com/Invis1ble/scrollbox.git
.bower install scrollbox
.npm install scrollbox
.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)
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)
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;
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)
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)
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)
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)
The distance in pixels for one fixed step of mouse wheel., (*26)
You probably shouldn't change this value., (*27)
Swipe acceleration factor., (*28)
Threshold time in milliseconds for detect inertial moving at swipe., (*29)
Normally you don't need to change this templates, but you can if you want., (*30)
You can call some methods of the plugin., (*31)
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');
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);
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');
Completely removes all stuff from the element., (*45)
Scrollbox triggers a several events during lifecycle., (*46)
Triggered when scrolling reach the left boundary of the content. Respects distanceToReach.x
option., (*47)
Triggered when scrolling reach the right boundary of the content. Respects distanceToReach.x
option., (*48)
Triggered when scrolling reach the top boundary of the content. Respects distanceToReach.y
option., (*49)
Triggered when scrolling reach the bottom boundary of the content. Respects distanceToReach.y
option., (*50)
var $container = $('#content-container'); $container .on('reachbottom.scrollbox', function () { $.ajax({ // options }).done(function (response) { $container .append(response) .scrollbox('update'); }); }) .scrollbox({ distanceToReach: { y: 100 } });
The MIT License, (*51)