-
Notifications
You must be signed in to change notification settings - Fork 43
/
utils.js
48 lines (42 loc) · 861 Bytes
/
utils.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
function throttle(fn, threshold, scope) {
threshold || (threshold = 250);
var last,
deferTimer;
return function () {
var context = scope || this;
var now = +new Date,
args = arguments;
if (last && now < last + threshold) {
clearTimeout(deferTimer);
deferTimer = setTimeout(function () {
last = now;
fn.apply(context, args);
}, threshold);
} else {
last = now;
fn.apply(context, args);
}
};
}
function debounce(fn, delay) {
var timer = null;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}
var ge = (function(){
var map = new Map();
return function( id ) {
var el = map.get( id );
if( el ) {
} else {
el = document.getElementById( id );
map.set( id, el );
}
return el;
}
})();