Skip to content

Which function is the actual callback function when switching the theme mode? #111

Answered by HEIGE-PCloud
zhaoyiluo asked this question in Q&A
Discussion options

You must be logged in to vote

Unfortunately, you need to modify src/js/theme.js.

Start from line 83, the function initSwitchTheme is the one you need to modify.

initSwitchTheme() {
    this.util.forEach(document.getElementsByClassName('theme-switch'), $themeSwitch => {
        $themeSwitch.addEventListener('click', () => {
            let currentTheme = document.body.getAttribute('theme');
            if (currentTheme === 'dark') {
                document.body.setAttribute('theme', 'black');
                window.localStorage && localStorage.setItem('theme', 'black');
                this.isDark = true;
            } else if (currentTheme === 'black') {
                document.body.setAttribute('theme', 'light');

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@zhaoyiluo
Comment options

Answer selected by zhaoyiluo
Comment options

You must be logged in to vote
4 replies
@HEIGE-PCloud
Comment options

@zhaoyiluo
Comment options

@HEIGE-PCloud
Comment options

@zhaoyiluo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants