-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscroll-to.js
23 lines (22 loc) · 1.04 KB
/
scroll-to.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// http://lions-mark.com/jquery/scrollTo/
// $('body').scrollTo('#target');
// $('#content').scrollTo(500);
// $('body').scrollTo('#post-5', { duration:'slow', offsetTop : '50' });
// $('body').scrollTo('#target', {}, complete_callback);
$.fn.scrollTo = function( target, options, callback ) {
if(typeof options == 'function' && arguments.length == 2){ callback = options; options = target; }
var settings = $.extend({
scrollTarget : target,
offsetTop : 50,
duration : 500,
easing : 'swing'
}, options);
return this.each(function(){
var scrollPane = $(this);
var scrollTarget = (typeof settings.scrollTarget == "number") ? settings.scrollTarget : $(settings.scrollTarget);
var scrollY = (typeof scrollTarget == "number") ? scrollTarget : scrollTarget.offset().top + scrollPane.scrollTop() - parseInt(settings.offsetTop);
scrollPane.animate({scrollTop : scrollY }, parseInt(settings.duration), settings.easing, function(){
if (typeof callback == 'function') { callback.call(this); }
});
});
}