-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathjQuery.scrollSpeed.js
More file actions
executable file
·65 lines (35 loc) · 1.62 KB
/
jQuery.scrollSpeed.js
File metadata and controls
executable file
·65 lines (35 loc) · 1.62 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Custom scrolling speed with jQuery
// Source: github.com/ByNathan/jQuery.scrollSpeed
// Version: 1.0
(function($) {
jQuery.scrollSpeed = function(step, speed) {
var $document = $(document),
$window = $(window),
$body = $('html, body'),
viewport = $window.height(),
top = 0,
scroll = false;
if (window.navigator.msPointerEnabled)
return false;
$window.on('mousewheel DOMMouseScroll', function(e) {
scroll = true;
if (e.originalEvent.wheelDeltaY < 0 || e.originalEvent.detail > 0)
top = (top + viewport) >= $document.height() ? top : top += step;
if (e.originalEvent.wheelDeltaY > 0 || e.originalEvent.detail < 0)
top = top <= 0 ? 0 : top -= step;
$body.stop().animate({
scrollTop: top
}, speed, 'default', function() {
scroll = false;
});
return false;
}).on('scroll', function() {
if (!scroll) top = $window.scrollTop();
}).on('resize', function() {
viewport = $window.height();
});
};
jQuery.easing.default = function (x,t,b,c,d) {
return -c * ((t=t/d-1)*t*t*t - 1) + b;
};
})(jQuery);