fix(theme): css filter breaking fixed position (#125)

Add css filters to `html` instead of `body`
This commit is contained in:
ZhaoBin 2020-12-11 16:57:04 +08:00 committed by GitHub
parent d023fb1374
commit c911af4aca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,11 +15,11 @@ export function setCssVar(prop: string, val: any, dom = document.documentElement
dom.style.setProperty(prop, val); dom.style.setProperty(prop, val);
} }
function toggleClass(flag: boolean, clsName: string) { function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
const body = document.body; const targetEl = target || document.body;
let { className } = body; let { className } = targetEl;
className = className.replace(clsName, ''); className = className.replace(clsName, '');
document.body.className = flag ? `${className} ${clsName} ` : className; targetEl.className = flag ? `${className} ${clsName} ` : className;
} }
/** /**
@ -27,7 +27,7 @@ function toggleClass(flag: boolean, clsName: string) {
* @param gray * @param gray
*/ */
export const updateColorWeak = (colorWeak: boolean) => { export const updateColorWeak = (colorWeak: boolean) => {
toggleClass(colorWeak, 'color-weak'); toggleClass(colorWeak, 'color-weak', document.documentElement);
}; };
/** /**
@ -35,7 +35,7 @@ export const updateColorWeak = (colorWeak: boolean) => {
* @param gray * @param gray
*/ */
export const updateGrayMode = (gray: boolean) => { export const updateGrayMode = (gray: boolean) => {
toggleClass(gray, 'gray-mode'); toggleClass(gray, 'gray-mode', document.documentElement);
}; };
/** /**