AddScroll plugin

This plugin will add a vertical scrollbar to a layer which has content deeper than its container parent. It will watch if the window has resized, and adjusts itself. The content can be scrolled on devices with touch interface too.

Syntax

$(layer).addScroll({ options });

options
  • enableKeyboard Enable PgUp and PgDn keys (default = true)
  • enableMouseWheel Enable the mouse wheel (default = true)
  • enableDrag Enable dragging the content with the mouse or touch (default = true) Please note, this functionality disables selecting text content within the layer.
  • dragMinSize the minimum size of the scroll handle (default = 10px)
  • speed the speed of the scrolling (default = 250ms)
  • effect the scrolling animation effect (default = ‘easeOutBack’) Other options: ‘swing’ and ‘linear’
  • disabledOpacity the disabled elements opacity (default = 0.3) (e.g. scroll up button when at the top)
  • wheelIncr the pixels to scroll on one mousewheel (default = 50)
  • rounding rounding radius of the scrollbar (default = 10px)
  • shadows CSS3 shadow effects (default = true)
  • gap the horizontal gap between the content and the scrollbar (default = 3px)

Example

sample.html
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>addScroll plugin sample</title> <style> body { margin:0; padding:0; font:12px/1.231 Arial,Helvetica,sans-serif; background-color:#BCB4AE; } #wrap { margin:10px auto; width:90%; height:280px; overflow:hidden; } #content { background-color:#fe9; } #content ul { margin:0; padding:10px; } #content ul li { float:left; display:inline-block; width:80px; text-align:center; margin:10px; padding:0.2em 0.6em; font-size:5em; background-color:#ffc; } </style> </head> <body> <div id="wrap"> <div id="content"> <ul> <li>A</li><li>B</li><li>C</li><li>D</li><li>E</li><li>F</li><li>G</li><li>H</li><li>I</li><li>J</li><li>K</li><li>L</li><li>M</li><li>N</li><li>O</li><li>P</li><li>Q</li><li>R</li><li>S</li><li>T</li><li>U</li><li>V</li><li>W</li><li>X</li><li>Y</li><li>Z</li> </ul> <div style="clear:both;"></div> </div> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js?ver=1.7.1"></script> <script src="addscroll.js"></script> <script> $(document).ready(function() { $('#content').addScroll(); }); </script> </body> </html>

Requirements

jQuery 1.7 or higher

License

Available for use in all personal or commercial projects under both MIT and GPL licenses.

Copyright (c) 2012 Laszlo Molnar

Leave a Reply