0%
没有时间学习的人,是有了时间也不会学习的人!
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title>CodePen - 🌜/🌞 Mode</title> <link rel="stylesheet" href="./style.css">
</head> <body>
<div class="container"> <div class="header"> <img class="sun" src="data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTkuMC4wLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDUxMiA1MTI7IiB4bWw6c3BhY2U9InByZXNlcnZlIiB3aWR0aD0iNTEycHgiIGhlaWdodD0iNTEycHgiPgo8cGF0aCBzdHlsZT0iZmlsbDojRkZBNjAwOyIgZD0iTTUwNy44MzQsMzAxLjYwOGwtNTQuNzY5LTQ4LjMxMmw1Mi44MzItNTAuMzk5YzEuOTQxLTEuODUyLDIuNzQtNC41OTEsMi4wOTktNy4xODkgIGMtMC42NDItMi41OTctMi42MjktNC42NTUtNS4yMTEtNS40MDFsLTcwLjMxNi0yMC4yOTJsMjUuOTg4LTY4LjA1NmMwLjk1NS0yLjUsMC40OTUtNS4zMTYtMS4yMDQtNy4zODkgIGMtMS43LTIuMDcyLTQuMzgzLTMuMDg1LTcuMDM4LTIuNjU3bC03Mi4yNzQsMTEuNjU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LDExNC45ODQgMjYzLjIsMTEwLjU1MiAgIi8+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPGc+CjwvZz4KPC9zdmc+Cg==" /> </div> <div class="content"> <h1>Hello</h1> <p>Click the sun/moon</p> </div> </div>
<script src="./script.js"></script>
</body> </html>
|
CSS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| :root { --primary-color: #1B1E24; --secondary-color: #1B1E24; --font-color: #1B1E24; --bg-color: #fff; --heading-color: #1B1E24; }
[data-theme=dark] { --primary-color: #fff; --secondary-color: #fff; --font-color: #fff; --bg-color: #1B1E24; --heading-color: #fff; }
body { background-color: var(--bg-color); }
.container { position: relative; display: flex; justify-content: center; align-items: center; text-align: center; height: 97vh; } .container .content h1 { color: var(--primary-color); font-family: "Dosis", sans-serif; font-size: 5rem; } .container .content p { color: var(--primary-color); font-family: "Dosis", sans-serif; font-size: 2rem; }
.header { position: absolute; top: 10px; right: 20px; } .header .moon, .header .sun { width: 34px; cursor: pointer; transition: 0.5s all ease-in-out; } .header .sun:hover { -webkit-animation: sun_rotate 1s infinite; animation: sun_rotate 1s infinite; } .header .moon:hover { transform: scale(1.1); } .header .hide { display: none; }
@-webkit-keyframes sun_rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes sun_rotate { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
JS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| const lightMode = document.querySelector('.sun'); const darkMode = document.querySelector('.moon');
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
lightMode.onclick = function(){ document.documentElement.setAttribute('data-theme', 'dark'); lightMode.style = "display: none"; darkMode.style = "display: block"; localStorage.setItem('theme', 'dark'); }
darkMode.onclick = function(){ document.documentElement.setAttribute('data-theme', 'light'); lightMode.style = "display: block"; darkMode.style = "display: none"; localStorage.setItem('theme', 'light'); }
if (currentTheme) { document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') { lightMode.style = "display: none"; darkMode.style = "display: block"; } }
|