Demo of Toss An animated scroll function.

Toss Docs

Toss is a JavaScript function that scrolls any overflow container to a set of coordinates using an animated duration. It will work on any element with overflow set to hidden, scroll,, or auto. Since overflow scrolling does not work in every browser, we highly recommend only using overflow on content that is accessible through additional means, such as with anchor links that point to each "slide" in a horizontal-overflow container.

It has no dependencies. Just call toss(), and pass a reference to an element and a set of options. For example, this script finds an element with an ID of "demo", and scrolls it to top: 300, left: 300 over the course of 5 seconds:


var demoElement = document.getElementById( "demo" );
toss( demoElement, { left: 300, top: 300, duration: 5000 } );

API & Options

In addition to left, top, and duration, there are other options. Here they are with their defaults and acceptable values:

Methods & properties

The toss object exposes three properties:

Example

In the following example, there's a list of numbers in an overflow container that is styled with dimensions that allow its child content to scroll in both directions. The list items are styled to fill the container's width and height 100%, so only one shows at a time. The links above the scrolling container are linked to each respective slide, but some JavaScript is bound to them to use the toss function to scroll to the list item smoothly.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6