File tree Expand file tree Collapse file tree 2 files changed +26
-25
lines changed
packages/vuepress-theme-reco/components Expand file tree Collapse file tree 2 files changed +26
-25
lines changed Original file line number Diff line number Diff line change @@ -9,19 +9,20 @@ function activateMode (mode) {
99 }
1010}
1111
12- // Dark and Light autoswitches
13- const onDark = ( e ) => e . matches && activateMode ( 'dark' )
14- const onLight = ( e ) => e . matches && activateMode ( 'light' )
15-
16- const darkScheme = window . matchMedia ( '(prefers-color-scheme: dark)' )
17- const lightScheme = window . matchMedia ( '(prefers-color-scheme: light)' )
18-
1912/**
2013 * Sets a color scheme for the website.
2114 * If browser supports "prefers-color-scheme", 'auto' mode will respect the setting for light or dark mode
2215 * otherwise it will set a dark theme during night time
2316 */
2417export default function setMode ( mode = 'auto' ) {
18+ // Dark and Light autoswitches
19+ // 这里的声明需要挪到 setMode 函数中,否则 windows 会报错
20+ const onDark = ( e ) => e . matches && activateMode ( 'dark' )
21+ const onLight = ( e ) => e . matches && activateMode ( 'light' )
22+
23+ const darkScheme = window . matchMedia ( '(prefers-color-scheme: dark)' )
24+ const lightScheme = window . matchMedia ( '(prefers-color-scheme: light)' )
25+
2526 if ( mode !== 'auto' ) {
2627 darkScheme . removeListener ( onDark )
2728 lightScheme . removeListener ( onLight )
Original file line number Diff line number Diff line change @@ -52,33 +52,33 @@ export default {
5252 this .refreshIndex ()
5353 }
5454 },
55-
56- mounted () {
55+
56+ mounted () {
5757 this .isInViewPortOfOne ()
5858 },
59-
59+
6060 updated : function () {
6161 this .isInViewPortOfOne ()
6262 },
6363
6464 methods: {
6565 isInViewPortOfOne () {
66- let siderbarScroll = document .getElementsByClassName (" sidebar" )[0 ]
67- let el = document .getElementsByClassName (" active sidebar-link" )[1 ]
68- if (el == null || el .offsetTop == undefined ) {
69- el = document .getElementsByClassName (" active sidebar-link" )[0 ]
70- }
71- if (el == null || el .offsetTop == undefined ) return
72-
73- const viewPortHeight = siderbarScroll .clientHeight || window .innerHeight || document .documentElement .clientHeight || document .body .clientHeight
74- let offsetBottom = el .offsetTop + el .offsetHeight
75- let scrollTop = siderbarScroll .scrollTop
76- let isView = (offsetBottom <= viewPortHeight + scrollTop)
77- if (! isView) {
78- siderbarScroll .scrollTop = (offsetBottom+ 5 - viewPortHeight)
79- }
66+ const siderbarScroll = document .getElementsByClassName (' sidebar' )[0 ]
67+ let el = document .getElementsByClassName (' active sidebar-link' )[1 ]
68+ if (el === null || el .offsetTop == undefined ) {
69+ el = document .getElementsByClassName (' active sidebar-link' )[0 ]
70+ }
71+ if (el === null || el .offsetTop == undefined ) return
72+
73+ const viewPortHeight = siderbarScroll .clientHeight || window .innerHeight || document .documentElement .clientHeight || document .body .clientHeight
74+ const offsetBottom = el .offsetTop + el .offsetHeight
75+ const scrollTop = siderbarScroll .scrollTop
76+ const isView = (offsetBottom <= viewPortHeight + scrollTop)
77+ if (! isView) {
78+ siderbarScroll .scrollTop = (offsetBottom + 5 - viewPortHeight)
79+ }
8080 },
81-
81+
8282 refreshIndex () {
8383 const index = resolveOpenGroupIndex (
8484 this .$route ,
You can’t perform that action at this time.
0 commit comments