github:
https://github.com/ColinEspinas/darken
在<head>添加:
<script src="https://unpkg.com/darken"></script> <script> const darkmode = new darken(); </script>
添加一个button:
<!-- index.html --> <button id="darkmode-button">Toggle dark mode</button> <script src="path/to/darken"></script> <script> const darkmode = new darken({ class: "darkmode-active", variables: { "--primary-color" : ["#000000", "#fafafa"], "--background-color" : ["#fafafa", "#000000"] }, toggle: "#darkmode-button", }); </script>
demo:
https://colinespinas.github.io/darken/