-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
64 lines (53 loc) · 1.23 KB
/
index.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Module dependencies.
*/
var prefixed = require('prefixed');
/**
* Expose `fade`.
*/
module.exports = fade;
/**
* Fade `el` to `opacity` in `duration` seconds.
*
* @param {Element} el
* @param {Number} opacity
* @param {Number=} duration
* @param {Function=} callback
*
* @todo Add other vendor prefixes
* @todo Properly clear transition
*/
function fade (el, opacity, duration, callback) {
if (typeof duration === 'undefined') duration = 1000;
else if (typeof duration === 'function') {
callback = duration;
duration = 1000;
}
var oldTransition = prefixed.get(el.style, 'transition') || '';
prefixed(el.style, 'transition', 'opacity ' + (duration/1000) + 's');
el.style.opacity = opacity;
setTimeout(function () {
prefixed(el.style, 'transition', oldTransition);
if (callback) callback();
}, duration);
}
/**
* Fade in `el`.
*
* @param {Element} el
* @param {Number=} duration
* @param {Function=} callback
*/
fade.out = function (el, duration, callback) {
fade(el, 0, duration, callback);
};
/**
* Fade out `el`.
*
* @param {Element} el
* @param {Number=} duration
* @param {Function=} callback
*/
fade['in'] = function (el, duration, callback) {
fade(el, 1, duration, callback);
};