forked from PaulAdamDavis/Arctic-Scroll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.arctic_scroll.js
More file actions
36 lines (31 loc) · 1.38 KB
/
jquery.arctic_scroll.js
File metadata and controls
36 lines (31 loc) · 1.38 KB
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 ($) {
$.fn.arctic_scroll = function (options) {
var defaults = {
elem: $(this),
speed: 500,
scroll_selector: 'html,body'
};
var options = $.extend(defaults, options),
to_scroll = options.scroll_selector,
ua = $.browser;
if ( ua.msie && ua.version.slice(0,1) == "8" ) {
to_scroll = window;
} else if ( ua.msie && ua.version.slice(0,1) == "7" ) {
to_scroll = window;
}
options.elem.click(function(event){
event.preventDefault();
var offset = ($(this).attr('data-offset')) ? $(this).attr('data-offset') : false,
position = ($(this).attr('data-position')) ? $(this).attr('data-position') : false;
if (offset) {
var toMove = parseInt(offset);
$(options.scroll_selector).stop(true, false).animate({scrollTop: ($(this.hash).offset().top + toMove) }, options.speed);
} else if (position) {
var toMove = parseInt(position);
$(options.scroll_selector).stop(true, false).animate({scrollTop: toMove }, options.speed);
} else {
$(options.scroll_selector).stop(true, false).animate({scrollTop: ($(this.hash).offset().top) }, options.speed);
}
});
};
})(jQuery);