Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

黑白主题切换 #416

Open
Pcjmy opened this issue Jan 20, 2023 · 2 comments
Open

黑白主题切换 #416

Pcjmy opened this issue Jan 20, 2023 · 2 comments

Comments

@Pcjmy
Copy link
Contributor

Pcjmy commented Jan 20, 2023

No description provided.

@morp-hex
Copy link

morp-hex commented Apr 4, 2023

<button>关灯</button>
    <script>
        var btn = document.querySelector('button');
        var bd = document.querySelector('body');
        btn.onclick = function () {
            if (btn.innerHTML === '关灯') {
                bd.style.backgroundColor = '#111';
                btn.innerHTML = '开灯';
            }
            else {
                bd.style.backgroundColor = '#fff';
                btn.innerHTML = '关灯';
            }
        }
    </script>

@huccct
Copy link

huccct commented May 5, 2023

纯css版本

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .content {
        width: 100%;
        height: 600px;
        transition: all 1s;
      }
      #modeCheckBox {
        display: none;
      }
      #modeCheckBox:checked + .content {
        background-color: black;
        color: white;
        transition: all 1s;
      }
      #modeBtn {
        font-size: 2rem;
        float: right;
      }
      #modeBtn::after {
        content: '🌞';
      }
      #modeCheckBox:checked + .content #modeBtn::after {
        content: '🌜';
      }
    </style>
  </head>
  <body>
    <input id="modeCheckBox" type="checkbox" />
    <div class="content">
      <header>
        <label id="modeBtn" for="modeCheckBox"></label>
      </header>
    </div>
  </body>
</html>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants