nanoScrollerJS is a jQuery plug-in that uses a simple way to achieve the scroll bar effect of Mac OS X Lion system. This scrollbar plugin uses minimal HTML structure .nano > .nano-content . Other scroll bar elements .pane > .nano-slider are dynamically loaded when the plugin is running. This scrollbar plug-in uses native scrollbars to work on iPad, iPhone and some Android Tablets.
How to use
HTML structure
The following is the HTML structure necessary for the scroll bar plug-in to work:
The class names of nano and nano-content can be changed through plug-in parameters (after the change, the CSS file of the plug-in must also be changed accordingly).
CSS style
Introduce nanoscroller.css file into HTML
You have to specify a width and height for the container and customize some basic styles for your scrollbar, for example:
JAVASCRIPT
Introduce jquery.nanoscroller.js file into the page.
Then use the following method to call the scroll bar plug-in. This method will be applied to all DOM elements with .nano in HTML:
Advanced methods
Scroll to top:
Scroll to bottom:
Scroll to the top with an offset:
Scroll to the bottom with an offset value:
Scroll an element:
Stop scrolling. This option will invalidate all bound events of the scrollbar plug-in and hide the scrollbar from the UI.
destroy
Destroy the nanoScroller scroll bar and reset the scroll bar to the browser's native scroll bar:
Set the scroll bar to flash. The flashing time is set by parameters (default 1.5 seconds).
nanoScroller();
Refresh the scroll bar. This operation will simply recalculate the position and height of the scroll bar:
Custom events
scrollend
A custom scrollend event will be triggered every time the scroll bar scrolls to the bottom of the container. (When the scroll bar has reached the bottom of the container, this event will not be triggered when the user scrolls again)
Some browsers will trigger this event multiple times at the same time, so jQuery .bind or .on should be used to bind this event. You can use the jquery-debounce plugin to cause the browser to trigger this event every 100 milliseconds:
scrolltop
Same as scrollend event, it is triggered every time the user scrolls to the top of the container.
The scrollend event is the same as the scrolltop event, it fires every time the user scrolls. This event comes with js object parameters of the current position, maximum height and direction (up or down) of the scroll bar:
Configuration parameters
There is a set of parameters available in this scroll bar plug-in:
iOSNativeScrolling
If you want to use native scrollbars in iOS 5, you can set it to true . Native scrollbars will work better in iOS 5.
Note that when iOSNativeScrolling is set to true, .pane and .slider will not be generated/added by the device to support native scroll bars.
Default value: false.
sliderMinHeight
Set the minimum height of the scroll element:
Default value: 20.
sliderMaxHeight
Set the maximum height of the scroll element:
Default value: null.
preventPageScrolling
Set to true to prevent the page from scrolling when the container content scrolls to the top or bottom:
Default value: false.
disableResize
Set to true to prevent nanoscroller from changing size. If you set this option to true, remember to call the reset method, otherwise strange problems will occur:
Default value: false.
alwaysVisible
Set to true to turn off the automatic hiding function when the scroll bar stops:
Default value: false.
flashDelay
When you enable the flash option, this option is used to specify the flash delay:
Default value: 1500.
paneClass
The class name of the scroll bar track element. If you modify it, you need to make corresponding changes in the CSS file:
Default: 'nano-pane'.
contentClass
The class name of the scroll bar container div. If you modify it, you need to make corresponding changes in the CSS file:
Default: 'nano-content'.
tabIndex
Set the order of scrollable content. When set to -1, using the tab key will skip the content:
Default value: 0.
Browser compatible
Desktop
IE7
Firefox 3
Chrome
Safari 4
Opera 11.60
Mobile devices
iOS 5 (iPhone, iPad and iPod Touch)
iOS 4 (comes with a plug-in)
Android Firefox
Android 2.2/2.3 native browser (comes with a plug-in)
Android Opera 11.6 (comes with a plug-in)
Better run nanoScroller in mobile device browsers through plug-ins
You can use overthrow.js to make nanoScroller work better on mobile browsers. It simulates CSS overflow ( overflow: auto;/overflow: scroll; ) on mobile devices.
To use overthrow, introduce overthrow.js into the page:
Then add overthrow class in your scrollbar content div:
The above is about how to use the nanoscroller plug-in. I hope you will like it.