Skip to content

predefined/jquery-smoothscroll

Repository files navigation

jquery-smoothscroll.js

A jQuery plugin for smooth page scrolling.

Bower version Built with Grunt Bitdeli Badge

What it does

SmoothScroll introduces the smoothScrollTop function that makes the browser smoothly scroll to the specified element.

How to use

If you have a webpage you want to scroll on, simply add jQuery and the plugin to your references. If you did that, simply get the element you want to scroll to and execute smoothScrollTop();.

API

General usage:

$(selector).smoothScrollTop([options]);

Options

  • duration: int
    The time of the scroll animation in ms. Defaults to 500.
  • offset: int
    Offset from the top of the specified element. Defaults to 0.
  • element: jQuery-Element
    The element to scroll on. Defaults to the selected element.
  • parent: jQuery-Element
    The parent the scroll should be done on. Defaults to $("body").
  • done: Function
    A callback that will be called when the function quits. Defaults to nothing.
  • scrollInvisibles: bool
    Determines whether invisible objects should be valid targets. Defaults to false.
  • debug: bool
    Determines whether debug messages (for bug finding) should be displayed. Defaults to false.

Examples

Scroll to header
$("header").smoothScrollTop();
Scroll to element with id="textfield" in 1s
$("#textfield").smoothScrollTop({
    duration: 1000
});

Tests

To run the test, execute grunt test. JSHint and QUnit will be run.

Minify

To create the .min version as well as the sourcemap, simply run grunt.

How it came into being

When developing our own website we needed a smooth scrolling plugin. None of those we found was actually working. That's why we decided to develop our own jQuery plugin for that.
Done by @sgade.

About

A smooth scrolling plugin for jQuery.

Resources

Stars

Watchers

Forks

Packages

No packages published