Commit c911af4aca49e6f9fe099e74a4d454286554e181

Authored by ZhaoBin
Committed by GitHub
1 parent d023fb13

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

Add css filters to `html` instead of `body`
Showing 1 changed file with 6 additions and 6 deletions
src/setup/theme/index.ts
@@ -15,11 +15,11 @@ export function setCssVar(prop: string, val: any, dom = document.documentElement @@ -15,11 +15,11 @@ export function setCssVar(prop: string, val: any, dom = document.documentElement
15 dom.style.setProperty(prop, val); 15 dom.style.setProperty(prop, val);
16 } 16 }
17 17
18 -function toggleClass(flag: boolean, clsName: string) {  
19 - const body = document.body;  
20 - let { className } = body; 18 +function toggleClass(flag: boolean, clsName: string, target?: HTMLElement) {
  19 + const targetEl = target || document.body;
  20 + let { className } = targetEl;
21 className = className.replace(clsName, ''); 21 className = className.replace(clsName, '');
22 - document.body.className = flag ? `${className} ${clsName} ` : className; 22 + targetEl.className = flag ? `${className} ${clsName} ` : className;
23 } 23 }
24 24
25 /** 25 /**
@@ -27,7 +27,7 @@ function toggleClass(flag: boolean, clsName: string) { @@ -27,7 +27,7 @@ function toggleClass(flag: boolean, clsName: string) {
27 * @param gray 27 * @param gray
28 */ 28 */
29 export const updateColorWeak = (colorWeak: boolean) => { 29 export const updateColorWeak = (colorWeak: boolean) => {
30 - toggleClass(colorWeak, 'color-weak'); 30 + toggleClass(colorWeak, 'color-weak', document.documentElement);
31 }; 31 };
32 32
33 /** 33 /**
@@ -35,7 +35,7 @@ export const updateColorWeak = (colorWeak: boolean) => { @@ -35,7 +35,7 @@ export const updateColorWeak = (colorWeak: boolean) => {
35 * @param gray 35 * @param gray
36 */ 36 */
37 export const updateGrayMode = (gray: boolean) => { 37 export const updateGrayMode = (gray: boolean) => {
38 - toggleClass(gray, 'gray-mode'); 38 + toggleClass(gray, 'gray-mode', document.documentElement);
39 }; 39 };
40 40
41 /** 41 /**