-
Notifications
You must be signed in to change notification settings - Fork 0
/
fade.js
27 lines (23 loc) · 1.01 KB
/
fade.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
var fade = function (type, ms, el, callback, cel) {
var isIn = type === 'in',
oppStatus = isIn ? 'out' : 'in',
opacity = isIn ? 0 : 1,
interval = 50,
gap = interval / ms;
if (isIn) {
el.style.display = 'block';
el.style.opacity = opacity;
}
function func() {
opacity = isIn ? opacity + gap : opacity - gap;
el.style.opacity = opacity;
if (opacity <= 0) el.style.display = 'none'
if (opacity <= 0 || opacity >= 1) {
window.clearInterval(fading);
if (typeof callback !== 'undefined' && typeof cel !== 'undefined') {
callback(oppStatus, ms, cel);
}
}
}
var fading = window.setInterval(func, interval);
}