-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
animatescroll.noeasing.js
50 lines (40 loc) · 1.52 KB
/
animatescroll.noeasing.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* @build : 20-07-2013
* @author : Ram swaroop
* @site : Compzets.com
*/
(function($){
$.fn.animatescroll = function(options) {
// fetches options
var opts = $.extend({},$.fn.animatescroll.defaults,options);
// make sure the callback is a function
if (typeof opts.onScrollStart == 'function') {
// brings the scope to the callback
opts.onScrollStart.call(this);
}
if(opts.element == "html,body") {
// Get the distance of particular id or class from top
var offset = this.offset().top;
// Scroll the page to the desired position
$(opts.element).stop().animate({ scrollTop: offset - opts.padding}, opts.scrollSpeed, opts.easing);
}
else {
// Scroll the element to the desired position
$(opts.element).stop().animate({ scrollTop: this.offset().top - this.parent().offset().top + this.parent().scrollTop() - opts.padding}, opts.scrollSpeed, opts.easing);
}
setTimeout(function() {
// make sure the callback is a function
if (typeof opts.onScrollEnd == 'function') {
// brings the scope to the callback
opts.onScrollEnd.call(this);
}
}, opts.scrollSpeed);
};
// default options
$.fn.animatescroll.defaults = {
easing:"swing",
scrollSpeed:800,
padding:0,
element:"html,body"
};
}(jQuery));