UNPKG

2.4 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4exports.flex = exports.transition = exports.animation = undefined;
5
6var _dom = require('./dom');
7
8var _object = require('./object');
9
10var animationEndEventNames = {
11 WebkitAnimation: 'webkitAnimationEnd',
12 OAnimation: 'oAnimationEnd',
13 animation: 'animationend'
14};
15
16var transitionEventNames = {
17 WebkitTransition: 'webkitTransitionEnd',
18 OTransition: 'oTransitionEnd',
19 transition: 'transitionend'
20};
21
22/**
23 * 是否支持某些动效事件,如果支持,返回相应的end事件名
24 * @private
25 * @param {Object<String>} names
26 * @return {Object|false}
27 */
28function _supportEnd(names) {
29 /* istanbul ignore if */
30 if (!_dom.hasDOM) {
31 return false;
32 }
33
34 var el = document.createElement('div');
35 var ret = false;
36
37 (0, _object.each)(names, function (val, key) {
38 /* istanbul ignore else */
39 if (el.style[key] !== undefined) {
40 ret = { end: val };
41 return false;
42 }
43 });
44
45 return ret;
46}
47
48/**
49 * 是否支持某些CSS属性
50 * @private
51 * @param {Object<Array<String>>} names
52 * @return {Boolean} is support
53 */
54function _supportCSS(names) {
55 /* istanbul ignore if */
56 if (!_dom.hasDOM) {
57 return false;
58 }
59
60 var el = document.createElement('div');
61 var ret = false;
62
63 (0, _object.each)(names, function (val, key) {
64 (0, _object.each)(val, function (item) {
65 try {
66 el.style[key] = item;
67 ret = ret || el.style[key] === item;
68 } catch (e) {
69 // It will be throw error when set unknown property under IE8
70 }
71 return !ret; // 如果有一个支持就返回false,后面不需要再判断
72 });
73
74 return !ret;
75 });
76
77 return ret;
78}
79
80/**
81 * 是否支持animation以及动画结束事件名
82 * @type {Object|false}
83 * @property {String} end 动画结束事件名
84 */
85var animation = exports.animation = _supportEnd(animationEndEventNames);
86
87/**
88 * 是否支持transition以及过滤效果结束事件名
89 * @type {Object|false}
90 * @property {String} end 过渡效果结束事件名
91 */
92var transition = exports.transition = _supportEnd(transitionEventNames);
93
94/**
95 * 是否支持flex属性
96 * @type {Boolean}
97 */
98var flex = exports.flex = _supportCSS({
99 display: ['flex', '-webkit-flex', '-moz-flex', '-ms-flexbox']
100});
\No newline at end of file