js+css实现带时钟显示时间的城市昼夜交替过渡动画效果代码
代码语言:html
所属分类:其他
代码描述:js+css实现带时钟显示时间的城市昼夜交替过渡动画效果代码,原理就是通过css调节照片的color、brightness、hue-rotate、opacity实现效果。
代码标签: js css 时钟 显示 时间 城市 昼夜 交替 过渡 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> :root { --filter-brightness: 2.4; --filter-contrast: 1.1; --filter-hue-rotate: 168deg; --filter-opacity: 1; --color: #111; } .ImageContainer img { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100vw; height: 100vh; object-fit: cover; } .ImageContainer::after { content: ""; position: absolute; inset: 0; backdrop-filter: brightness(var(--filter-brightness)) contrast(var(--filter-contrast)) hue-rotate(var(--filter-hue-rotate)); opacity: var(--filter-opacity); transition: opacity 2.5s linear; } /* other styles */ #Clock { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 90vw; color: var(--color); text-align: center; font-size: 3rem; font-weight: 700; text-shadow: 0 0 5px #fff; transition: color 2.5s; } label { display: inline-block; vertical-align: middle; position: relative; z-index: 1; padding: 20px; cursor: pointer; color: var(--color); font-size: 1.7rem; transition: 2.5s; } input { display: inline-block; vertical-align: middle; position: relative; z-index: 1; cursor: pointer; margin-left: 20px; width: 30px; height: 30px; } body { margin: 0; font-family: "Poppins", sans-serif; } * { box-sizing: border-box; } </style> </head> <body translate="no"> <main> <input id="NightToggle" type="checkbox" /> <label for="NightToggle">Toggle night</label> <div class="ImageContainer"> <img src="//repo.bfw.wiki/bfwrepo/image/64dc5ff1b6290.jpeg" /> </div> <span id="Clock"></span> </main> <script > const r = document.querySelector(':root'); const clockElement = document.getElementById('Clock'); const nightToggleElement = document.getElementById('NightToggle'); /* When checkbow is clicked */ nightToggleElement.addEventListener('change', () => { const isChecked = nightToggleElement.checked; const colorValue = isChecked ? "#eee" : "#111"; const brightnessValue = isChecked ? "0.5" : "2.4"; const hueRotateValue = isChecked ? "179deg" : "168deg"; /* Update CSS variables (immediately .........完整代码请登录后点击上方下载按钮下载查看
网友评论0