jquery.scrollto2.1.2 • Public • Published
Lightweight, cross-browser and highly customizable animated scrolling with jQuery
The plugin requires jQuery 1.8 or higher.
bower install jquery.scrollTo
npm install jquery.scrollto
php composer.phar require --prefer-dist flesler/jquery.scrollto "*"
Using a public CDN
CDN provided by jsdelivr
CDN provided by cdnjs
If you want the latest stable version, get the latest release from the releases page.
jQuery.scrollTo's signature is designed to resemble $().animate().
This must be a scrollable element, to scroll the whole window use
This defines the position to where
element must be scrolled. The plugin supports all these formats:
- A number with a fixed position:
- A string with a fixed position with px:
- A string with a percentage (of container's size):
- A string with a relative step:
- An object with
topcontainining any of the aforementioned:
- The string
"max"to scroll to the end.
- A string selector that will be relative to the element to scroll:
- A DOM element, probably a child of the element to scroll:
- A jQuery object with a DOM element:
duration parameter is a shortcut to the setting with the same name.
These are the supported settings:
- axis: The axes to animate:
- interrupt: If
truewill cancel the animation if the user scrolls. Default is
- limit: If
truethe plugin will not scroll beyond the container's size. Default is
- margin: If
true, subtracts the margin and border of the
targetelement. Default is
- offset: Added to the final position, can be a number or an object with
- over: Adds a % of the
- queue: If
truewill scroll one
axisand then the other. Default is
- onAfter(target, settings): A callback triggered when the animation ends (jQuery's
- onAfterFirst(target, settings): A callback triggered after the first axis scrolls when queueing
You can add any setting supported by $().animate() as well:
- duration: Duration of the animation, default is
0which makes it instantaneous
- easing: Name of an easing equation, you must register the easing function:
- fail(): A callback triggered when the animation is stopped (f.e via
- step(): A callback triggered for every animated property on every frame
- progress(): A callback triggered on every frame
- And more, check jQuery's documentation
You can use
$.scrollTo(...) as a shorthand for
Changing the default settings
As with most plugins, the default settings are exposed so they can be changed.
Stopping the animation
jQuery.scrollTo ends up creating ordinary animations which can be stopped by calling $().stop() or $().finish() on the same element you called
$().scrollTo(), including the
Remember you can pass a
fail() callback to be called when the animation is stopped.
Check the demo to see every option in action.
There are two plugins, also created by me that depend on jQuery.scrollTo and aim to simplify certain use cases.
This plugin makes it very easy to implement anchor navigation. If you don't want to include another plugin, you can try using something like this minimalistic gist.
This plugin simplifies the creation of scrolling slideshows.
(The MIT License)
Copyright (c) 2007-2015 Ariel Flesler firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.