2021-06-26 01:35:40 +00:00
|
|
|
import type { CSSProperties } from 'vue';
|
2020-10-13 14:26:56 +00:00
|
|
|
|
2020-05-13 10:36:53 +00:00
|
|
|
/**
|
|
|
|
* Easy to set element style, return previous style
|
|
|
|
* IE browser compatible(IE browser doesn't merge overflow style, need to set it separately)
|
|
|
|
* https://github.com/ant-design/ant-design/issues/19393
|
|
|
|
*
|
|
|
|
*/
|
2020-10-13 14:26:56 +00:00
|
|
|
export interface SetStyleOptions {
|
|
|
|
element?: HTMLElement;
|
|
|
|
}
|
|
|
|
function setStyle(style: CSSProperties, options: SetStyleOptions = {}): CSSProperties {
|
2020-05-13 10:36:53 +00:00
|
|
|
const { element = document.body } = options;
|
2020-10-13 14:26:56 +00:00
|
|
|
const oldStyle: CSSProperties = {};
|
2020-05-13 10:36:53 +00:00
|
|
|
|
|
|
|
const styleKeys = Object.keys(style);
|
|
|
|
|
|
|
|
// IE browser compatible
|
|
|
|
styleKeys.forEach(key => {
|
|
|
|
oldStyle[key] = element.style[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
styleKeys.forEach(key => {
|
|
|
|
element.style[key] = style[key];
|
|
|
|
});
|
|
|
|
|
|
|
|
return oldStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default setStyle;
|