$('a').smoothScroll();$('#container a').smoothScroll();$('#container a').smoothScroll({excludeWithin: ['.container2']});$('a').smoothScroll({exclude: ['.rough','#chunky']});$('.backtotop').smoothScroll({offset: -100});$('a').smoothScroll({afterScroll: function() { alert('we made it!'); }});The following options, shown with their default values, are available for both $.fn.smoothScroll and $.smoothScroll:
1234567891011121314151617181920212223242526 { offset: 0, // one of 'top' or 'left' direction: 'top', // only use if you want to override default behavior scrollTarget: null, // fn(opts) function to be called before scrolling occurs. // `this` is the element(s) being scrolled beforeScroll: function() {}, // fn(opts) function to be called after scrolling occurs. // `this` is the triggering element afterScroll: function() {}, easing: 'swing', speed: 400, // coefficient for "auto" speed autoCoefficent: 2, // $.fn.smoothScroll only: whether to prevent the default click action preventDefault: true }
The options object for $.fn.smoothScroll can take two additional properties:
exclude and excludeWithin. The value for both of these is an array of
selectors, DOM elements or jQuery objects. Default value for both is an
empty array.
$.smoothScroll()document.documentElement /
document.body)Doesn't automatically fire, so you need to bind it to some other user interaction. For example:
1234567 $('button.scrollsomething').on('click', function() { $.smoothScroll({ scrollElement: $('div.scrollme'), scrollTarget: '#findme' }); return false;});
The $.smoothScroll method can take one or two arguments.
scrollTarget option.The following option, in addition to those listed for $.fn.smoothScroll above, is available
for $.smoothScroll:
12345 { // jQuery set of elements you wish to scroll. // if null (default), $('html, body').firstScrollable() is used. scrollElement: null,}
.find() or .next()..find() or .next().$('html, body').firstScrollable().animate({scrollTop: someNumber},
someSpeed)$.fn.smoothScroll method looks
for an element with an id attribute that matches the <a> element's hash.
It does not look at the element's name attribute. If you want a clicked link
to scroll to a "named anchor" (e.g. <a name="foo">), you'll need to use the
$.smoothScroll method instead.$.fn.smoothScroll and $.smoothScroll methods use the
$.fn.firstScrollable DOM traversal method (also defined by this plugin)
to determine which element is scrollable. If no elements are scrollable,
these methods return a jQuery object containing an empty array, just like
all of jQuery's other DOM traversal methods. Any further chained methods,
therefore, will be called against no elements (which, in most cases,
means that nothing will happen).