Repository navigation
Expand file tree
/
Copy pathc.scroll.js
More file actions
68 lines (58 loc) · 1.54 KB
/
Copy pathc.scroll.js
File metadata and controls
68 lines (58 loc) · 1.54 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
66
67
68
// Scroll monitoring for DOM updates
// Usage:
// c.scroll();
// c.scroll({ classname: 'myscrollclass', timeout: 1000 });
(function(w, d, c) {
var defaults = {
classname : 'scroll',
timeout: 500
};
c.scroll = function( a, b ){
// Used to track the enabling of scroll effects
var enableTimer = 0;
// fallbacks
a = a || {};
b = b || {};
// cover the case of just sending a callback
if( typeof a == "function" ){
options = {};
callback = a;
} else if( typeof b == "function" ){
options = a;
callback = b;
} else {
options = a;
callback = false;
}
// extend defaults
options = c.extend( defaults, options );
// Inspired by: http://www.html5rocks.com/en/tutorials/speed/unnecessary-paints/
/*
* Listen for a scroll and use that to remove
* the possibility of scroll effects
*/
w.addEventListener('scroll', function() {
// trigger callback
if( callback ) callback();
//
clearTimeout(enableTimer);
addScrollClass();
// enable after 1 second, choose your own value here!
enableTimer = setTimeout(removeScrollClass, options.timeout);
}, false);
/**
* Removes the scroll class from the body. Hover styles
* may be reliant on this class being present
*/
function removeScrollClass() {
d.body.classList.remove( options.classname );
}
/**
* Adds the scroll class to the body. Hover styles
* may be reliant on this class being present
*/
function addScrollClass() {
d.body.classList.add( options.classname );
}
};
})(window, document, this.c);