-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.scrollTo.js
36 lines (34 loc) · 1.32 KB
/
jquery.scrollTo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function ($) {
var scrollSettings = { duration: 2000, top: 0, left: 0 };
$.scrollTo = function (options) {
/// <summary>Scrolls window to location defined by top and left</summary>
/// <param name="options" type="Object"></param>
if ($.isPlainObject(options)) {
$.extend(scrollSettings, options);
} else if ($.isNumeric(options)) {
scrollSettings.duration = options;
}
$('html, body').animate({
scrollTop: scrollSettings.top,
scrollLeft: scrollSettings.left
}, scrollSettings.duration);
};
var fnScrollSettings = { focus: true };
$.fn.scrollTo = function(options){
/// <summary>Scrolls window to element and calls focus to element, accepts duration in ms, this is chainable</summary>
/// <returns type="Object">jquery object</returns>
var self = this,
offsets = self.offset();
if($.isPlainObject(options)){
$.extend(fnScrollSettings, options);
}else if($.isNumeric(options)){
fnScrollSettings.duration = options;
}
$.extend(fnScrollSettings, offsets);
$.scrollTo(fnScrollSettings);
if(fnScrollSettings.focus){
self.focus();
}
return self;
};
})(jQuery);