jQuery Smooth Div Scroll by Thomas Kahn

Smooth Div Scroll is a jQuery plugin that scrolls content horizontally left or right.

Smooth Touch Scroll has just been released!

jQuery Smooth Touch Scroll

I have just released Smooth Touch Scroll, a slim touch version of Smooth Div Scroll. If Smooth Div Scroll is the Swiss Army Knife of smooth scrolling, Smooth Touch Scroll is the lightweight cousin, slimmed down and geared towards touch scrolling. Smooth Touch Scroll will still work on desktop computers that don't have touch (using drag scrolling) but it's primarily for touch devices.

Check out Smooth Touch Scroll att smoothtouchsroll.com

Consider using Smooth Touch Scroll if you don't need the full functionality of Smooth Div Scroll and if your content is primarily for touch devices.

Main features

Apart from many of the other scrolling plugins that have been written for jQuery, Smooth Div Scroll does not limit the scrolling to distinct steps. As the name of the plugin hints, scrolling is smooth. There are no other buttons or links on outside the scroller since the scrolling is done using your fingers (touch), hotspots, the mouse wheel or via auto scrolling. Unobtrusive and smooth is the key here.

Table of contents

  1. How does it work?
  2. Quick demo
  3. Basic demo (use as template)
  4. Download/GitHub
  5. More examples!
  6. Options
  7. Altering options after initialization
  8. Public methods
  9. Callbacks
  10. The CSS
  11. Dependencies
  12. Help, support and newsletter
  13. Version history and license
  14. About me
  15. Nice sites that use Smooth Div Scroll
  16. If you like this plugin

How does it work?

The basic principle behind Smooth Div Scroll is simple: let one div (scrollableArea) scroll inside another div (scrollWrapper). Two hotspots are used to trigger the actual scrolling (scrollingHotSpotLeft and scrollingHotSpotRight). You can also let the user scroll using touch, the mouse wheel or just let the scroller auto scroll. The scrollWrapper determines how much of the scrollableArea that should be visible - everything outside the scrollWrapper is hidden from view.

Illustration showing the different elements of Smooth Div Scroll

Quick demo

Here's a quick demo of Smooth Div Scroll in action. I've set the options so the user can scroll using the hotspots or the mouse wheel . I've also told the scroller to start auto scrolling as soon as the page loads and stop auto scrolling as soon as the user interacts with the scoller. Touch scrolling is not enabled for this particular demo - check out the touch demo if you want to try touch scrolling.

Field Gnome Pencils Golf River Train Leaf Dog

The jQuery code for this particular demo looks like this:


<script type="text/javascript">
	$(document).ready(function () {
		$("#makeMeScrollable").smoothDivScroll({
			mousewheelScrolling: "allDirections",
			manualContinuousScrolling: true,
			autoScrollingMode: "onStart"
		});
	});
</script>

In this particular demo I've set some options that override the default options:

I've used only a few of all the available options. You'll find all the options described here.) In the demo above the HTML-code looks like this:


	<div id="makeMeScrollable">
		<img src="images/demo/field.jpg" alt="Field" id="field" />
		<img src="images/demo/gnome.jpg" alt="Gnome" id="gnome" />
		<img src="images/demo/pencils.jpg" alt="Pencils" id="pencils" />
		<img src="images/demo/golf.jpg" alt="Golf" id="golf" />
		<img src="images/demo/river.jpg" alt="River" id="river" />
		<img src="images/demo/train.jpg" alt="Train" id="train" />
		<img src="images/demo/leaf.jpg" alt="Leaf" id="leaf" />
		<img src="images/demo/dog.jpg" alt="Dog" id="dog" />
	</div>

As you can see there is a surrounding div with the id makeMeScrollable. This is the element that I turn into a Smooth Div Scroll. Inside this div you can put any content - not just images.

Please note that you may have to give the elements that you put inside the scrollable area some styling to make sure that they are positioned like you want them. Here's a good template to start with:


#makeMeScrollable div.scrollableArea *
{
	position: relative;
	display: block
	float: left;
	margin: 0;
	padding: 0;
	/* If you don't want the images in the scroller to be selectable, try the following
		block of code. It's just a nice feature that prevent the images from
		accidentally becoming selected/inverted when the user interacts with the scroller. */
	-webkit-user-select: none;
	-khtml-user-select: none;
	-moz-user-select: none;
	-o-user-select: none;
	user-select: none;
}

In this example there's no space between the elements inside the scrollable area. If you want a space between them, use padding and not margin since margin tends to generate errors in Internet Explorer.

Back to table of contents

About me

Thomas Kahn dressed for the long Swedish winter

My name is Thomas Kahn and I live and work in Stockholm, Sweden. I've been working as a web developer for the past fourteen years.

Currently I'm working at the advertising agency Kärnhuset in central Stockholm, Sweden. When I'm not dabbling with jQuery I program in ASP.NET/C# and I also do a lot of HTML/CSS.

If you find a bug or want to make alterations of the code, please go to the Smooth Div Scroll page on GitHub.

Happy scrolling!

Back to table of contents

If you like this plugin

I've put hundreds of hours of work into this project. If you found this plugin useful and it saved you a lot of time on your latest project, please consider using Flattr or PayPal to show your appreciation.

Flattr

PayPal

You pay what you think it's worth to you - there's no preconfigured amount.

Back to table of contents