forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport.js
94 lines (80 loc) · 2.15 KB
/
support.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { hasDOM } from './dom';
import { each } from './object';
const animationEndEventNames = {
WebkitAnimation: 'webkitAnimationEnd',
OAnimation: 'oAnimationEnd',
animation: 'animationend',
};
const transitionEventNames = {
WebkitTransition: 'webkitTransitionEnd',
OTransition: 'oTransitionEnd',
transition: 'transitionend',
};
/**
* 是否支持某些动效事件,如果支持,返回相应的end事件名
* @private
* @param {Object<String>} names
* @return {Object|false}
*/
function _supportEnd(names) {
/* istanbul ignore if */
if (!hasDOM) {
return false;
}
const el = document.createElement('div');
let ret = false;
each(names, (val, key) => {
/* istanbul ignore else */
if (el.style[key] !== undefined) {
ret = { end: val };
return false;
}
});
return ret;
}
/**
* 是否支持某些CSS属性
* @private
* @param {Object<Array<String>>} names
* @return {Boolean} is support
*/
function _supportCSS(names) {
/* istanbul ignore if */
if (!hasDOM) {
return false;
}
const el = document.createElement('div');
let ret = false;
each(names, (val, key) => {
each(val, item => {
try {
el.style[key] = item;
ret = ret || el.style[key] === item;
} catch (e) {
// It will be throw error when set unknown property under IE8
}
return !ret; // 如果有一个支持就返回false,后面不需要再判断
});
return !ret;
});
return ret;
}
/**
* 是否支持animation以及动画结束事件名
* @type {Object|false}
* @property {String} end 动画结束事件名
*/
export const animation = _supportEnd(animationEndEventNames);
/**
* 是否支持transition以及过滤效果结束事件名
* @type {Object|false}
* @property {String} end 过渡效果结束事件名
*/
export const transition = _supportEnd(transitionEventNames);
/**
* 是否支持flex属性
* @type {Boolean}
*/
export const flex = _supportCSS({
display: ['flex', '-webkit-flex', '-moz-flex', '-ms-flexbox'],
});