import isBrowser from './isBrowser'; /** * 获取DOM元素的style * @param {HTMLElement} el dom元素 * @param {String} prop 样式属性 * @returns {String|Array>} */ export default function getStyle (el: any, prop: string|undefined): string|undefined|CSSStyleDeclaration { if (!el || !isBrowser()) { return; } let _res: CSSStyleDeclaration|string|undefined; if (window.getComputedStyle instanceof Function) { _res = window.getComputedStyle(el, null); } else { _res = el.currentStyle; } if (_res && prop) { _res = _res[prop]; } return _res; }