A jQuery plugin that offers a
is a jQuery plugin that offers a simple way of implementing Mac OS X Lion-styled scrollbars for your website.
It uses minimal HTML markup being .nano > .nano-content
. The other scrollbar div elements .pane > .nano-slider
are added during run time to prevent clutter in templating. The latest version utilizes native scrolling and works with the iPad, iPhone, and some Android Tablets.
Demo and deocumentation available here: jQuery nanoScroller docs
UsageInstallation
meteor add yasaricli:nanoscroller
To start using, you need three basic things:
1. MarkupThe following type of markup structure is needed to make the plugin work:
<div id="about" class="nano"> <div class="nano-content"> ... content here ... </div> </div>
Copy the HTML markup. Change .nano
into something related to your content. Though you can also remove that attribute as long as you have a parent div with an ID reference. e.g. #parent > .nano
. nano
and nano-content
classnames can be customized via plugin options (in that case you must rename them inside the plugin's CSS file as well).
You should specify a width and a height to your container, and apply some custom styling for your scrollbar. Here's an example:
.nano { background: #bba; width: 500px; height: 500px; } .nano > .nano-content { padding: 10px; } .nano > .nano-pane { background: #888; } .nano > .nano-pane > .nano-slider { background: #111; } 3. JavaScript
Running this script will apply the nanoScroller plugin to all DOM elements with a .nano
className.
$(".nano").nanoScroller(); Advanced methods scroll
To scroll at the top:
$(".nano").nanoScroller({ scroll: 'top' });
To scroll at the bottom:
$(".nano").nanoScroller({ scroll: 'bottom' });
To scroll at the top with an offset value:
$(".nano").nanoScroller({ scrollTop: value });
To scroll at the bottom with an offset value:
$(".nano").nanoScroller({ scrollBottom: value });
To scroll to an element:
$(".nano").nanoScroller({ scrollTo: $('#a_node') }); stop:
To stop the operation. This option will tell the plugin to disable all event bindings and hide the gadget scrollbar from the UI.
$(".nano").nanoScroller({ stop: true }); destroy:
Destroys nanoScroller and restores browser's native scrollbar.
$(".nano").nanoScroller({ destroy: true }); flash:
To flash the scrollbar gadget for an amount of time defined in plugin settings (defaults to 1,5s). Useful if you want to show the user (e.g. on pageload) that there is more content waiting for him.
$(".nano").nanoScroller({ flash: true }); nanoScroller();
Refresh the scrollbar. This simply re-calculates the position and height of the scrollbar gadget.
$(".nano").nanoScroller(); Custom events 'scrollend'
A custom 'scrollend'
event is triggered on the element every time the user has scrolled to the end of the content element (does not get triggered more than once when user tries to scroll down and has already reached the end of scrollable content).
$(".nano").bind("scrollend", function(e){ console.log("current HTMLDivElement", e.currentTarget); });
Some browsers trigger this event more than once each time, so to listen to the custom event, instead of using jQuery's normal .bind
or .on
, you most likely want to use this tiny jQuery debounce plugin to prevent browsers from firing your function more than once every 100ms.
$(".nano").debounce("scrollend", function() { alert("The end"); }, 100); 'scrolltop'
Same as the 'scrollend'
event, but it is triggered every time the user has scrolled to the top of the content element.
Same as the 'scrolltop'
and 'scrollend'
events, but it's triggered every time the user scrolls. It also carries a JavaScript object with the current position, the maximum height and the direction (up
or down
).
$(".nano").on("update", function(event, values){ console.debug( values ); }); Plugin Options
There are a few options that you can change when running nanoScroller, e.g. $(".nano").nanoScroller({ paneClass: 'myclass' });
Set to true if you want to use native scrolling in iOS 5+. This will disable your custom nanoScroller scrollbar in iOS 5+ and use the native one instead. While the native iOS scrollbar usually works much better, there could possibly be bugs in certain situations.
Notice that .pane
and .slider
elements are not generated/added for devices that support iOS native scrolling when iOSNativeScrolling
option is enabled.
Default: false
$(".nano").nanoScroller({ iOSNativeScrolling: true }); sliderMinHeight
Sets the minimum height of the slider element.
Default: 20
$(".nano").nanoScroller({ sliderMinHeight: 40 }); sliderMaxHeight
Sets the maximum height of the slider element.
Default: null
$(".nano").nanoScroller({ sliderMaxHeight: 200 }); preventPageScrolling
Set to true to prevent page scrolling when top or bottom inside the content div is reached.
Default: false
$(".nano").nanoScroller({ preventPageScrolling: true }); disableResize
Set to true to disable the resize from nanoscroller. Useful if you want total control of the resize event. If you set this option to true remember to call the reset method so that the scroll don't have strange behavior.
Default: false
$(".nano").nanoScroller({ disableResize: true }); alwaysVisible
Set to true to stop the scrollbar from auto-hiding itself.
Default: false
$(".nano").nanoScroller({ alwaysVisible: true }); flashDelay:
Use this setting to specify the scrollbar hide delay in milliseconds if you have enabled the flash
option.
$(".nano").nanoScroller({ flashDelay: 1000 });
Default: 1500
paneClassA classname for scrollbar track element. If you change this setting, you also have to change it in the plugin's CSS file.
Default: 'nano-pane'
$(".nano").nanoScroller({ paneClass: 'scrollPane' }); sliderClass
A classname for scrollbar thumb element. If you change this setting, you also have to change it in the plugin's CSS file.
Default: 'nano-slider'
$(".nano").nanoScroller({ sliderClass: 'scrollSlider' }); contentClass
A classname for your content div. If you change this setting, you also have to change it in the plugin's CSS file.
Default: 'nano-content'
$(".nano").nanoScroller({ contentClass: 'sliderContent' }); enabledClass
A classname for scrollbar enabled mode. If you change this setting, you also have to change it in the plugin's CSS file.
Default: 'has-scrollbar'
$(".nano").nanoScroller({ enabledClass: '__enabled' }); flashedClass
A classname for scrollbar flashed mode. If you change this setting, you also have to change it in the plugin's CSS file.
Default: 'flashed'
$(".nano").nanoScroller({ flashedClass: '__flashed' }); activeClass
A classname for scrollbar active mode. If you change this setting, you also have to change it in the plugin's CSS file.
Default: 'active'
$(".nano").nanoScroller({ activeClass: '__active' }); tabIndex
Set the tab order of the scrollable content. Set to -1 to skip over the scrollable content when tabbing.
Default: 0
$(".nano").nanoScroller({ tabIndex: 0 });
Copyright (c) 2012 James Florentino
Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。