You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
756 B
31 lines
756 B
import type { CSSProperties } from 'vue';
|
|
|
|
/**
|
|
* 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
|
|
*
|
|
*/
|
|
export interface SetStyleOptions {
|
|
element?: HTMLElement;
|
|
}
|
|
function setStyle(style: CSSProperties, options: SetStyleOptions = {}): CSSProperties {
|
|
const { element = document.body } = options;
|
|
const oldStyle: CSSProperties = {};
|
|
|
|
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;
|