Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
00
00
00
00
00
00
PM
AM
css
* { border: 0; box-sizing: border-box; margin: 0; padding: 0; } :root { --hue: 223; --bg: hsl(var(--hue),90%,90%); --fg: hsl(var(--hue),10%,10%); --primary: hsl(var(--hue),90%,55%); --trans-dur: 0.3s; font-size: calc(16px + (20 - 16) * (100vw - 320px) / (1280 - 320)); } body { background-color: var(--bg); color: var(--fg); font: 1em/1.5 "DM Sans", sans-serif; height: 100vh; display: grid; place-items: center; transition: background-color var(--trans-dur), color var(--trans-dur); } .clock { display: flex; flex-direction: column; flex-wrap: wrap; align-items: center; } .clock__block { background-color: hsl(var(--hue),10%,90%); border-radius: 0.5rem; box-shadow: 0 1rem 2rem hsla(var(--hue),90%,50%,0.3); font-size: 3em; line-height: 2; margin: 0.75rem; overflow: hidden; text-align: center; width: 6rem; height: 6rem; transition: background-color var(--trans-dur), box-shadow var(--trans-dur); } .clock__block--small { border-radius: 0.25rem; box-shadow: 0 0.5rem 2rem hsla(var(--hue),90%,50%,0.3); font-size: 1em; line-height: 3; width: 3rem; height: 3rem; } .clock__colon { display: none; font-size: 2em; opacity: 0.5; position: relative; } .clock__colon:before, .clock__colon:after { background-color: currentColor; border-radius: 50%; content: ""; display: block; position: absolute; top: -0.05em; left: -0.05em; width: 0.1em; height: 0.1em; transition: background-color var(--trans-dur); } .clock__colon:before { transform: translateY(-200%); } .clock__colon:after { transform: translateY(200%); } .clock__digit-group { display: flex; flex-direction: column-reverse; } .clock__digits { width: 100%; height: 100%; } .clock__block--bounce { animation: bounce 0.75s; } .clock__block--bounce .clock__digit-group { animation: roll 0.75s ease-in-out forwards; transform: translateY(-50%); } .clock__block--delay1, .clock__block--delay1 .clock__digit-group { animation-delay: 0.1s; } .clock__block--delay2, .clock__block--delay2 .clock__digit-group { animation-delay: 0.2s; } /* Dark theme */ @media (prefers-color-scheme: dark) { :root { --bg: hsl(var(--hue),10%,10%); --fg: hsl(var(--hue),10%,90%); } .clock__block { background-color: hsl(var(--hue),90%,40%); box-shadow: 0 1rem 2rem hsla(var(--hue),90%,60%,0.4); } .clock__block--small { box-shadow: 0 0.5rem 2rem hsla(var(--hue),90%,60%,0.4); } } /* Beyond mobile */ @media (min-width: 768px) { .clock { flex-direction: row; } .clock__colon { display: inherit; } } /* Animations */ @keyframes bounce { from, to { animation-timing-function: ease-in; transform: translateY(0); } 50% { animation-timing-function: ease-out; transform: translateY(15%); } } @keyframes roll { from { transform: translateY(-50%); } to { transform: translateY(0); } }
JavaScript
window.addEventListener("DOMContentLoaded",() => { const clock = new BouncyBlockClock(".clock"); }); class BouncyBlockClock { constructor(qs) { this.el = document.querySelector(qs); this.time = { a: [], b: [] }; this.rollClass = "clock__block--bounce"; this.digitsTimeout = null; this.rollTimeout = null; this.mod = 0 * 60 * 1000; this.loop(); } animateDigits() { const groups = this.el.querySelectorAll("[data-time-group]"); Array.from(groups).forEach((group,i) => { const { a, b } = this.time; if (a[i] !== b[i]) group.classList.add(this.rollClass); }); clearTimeout(this.rollTimeout); this.rollTimeout = setTimeout(this.removeAnimations.bind(this),900); } displayTime() { // screen reader time const timeDigits = [...this.time.b]; const ap = timeDigits.pop(); this.el.ariaLabel = `${timeDigits.join(":")} ${ap}`; // displayed time Object.keys(this.time).forEach(letter => { const letterEls = this.el.querySelectorAll(`[data-time="${letter}"]`); Array.from(letterEls).forEach((el,i) => { el.textContent = this.time[letter][i]; }); }); } loop() { this.updateTime(); this.displayTime(); this.animateDigits(); this.tick(); } removeAnimations() { const groups = this.el.querySelectorAll("[data-time-group]"); Array.from(groups).forEach(group => { group.classList.remove(this.rollClass); }); } tick() { clearTimeout(this.digitsTimeout); this.digitsTimeout = setTimeout(this.loop.bind(this),1e3); } updateTime() { const rawDate = new Date(); const date = new Date(Math.ceil(rawDate.getTime() / 1e3) * 1e3 + this.mod); let h = date.getHours(); const m = date.getMinutes(); const s = date.getSeconds(); const ap = h < 12 ? "AM" : "PM"; if (h === 0) h = 12; if (h > 12) h -= 12; this.time.a = [...this.time.b]; this.time.b = [ (h < 10 ? `0${h}` : `${h}`), (m < 10 ? `0${m}` : `${m}`), (s < 10 ? `0${s}` : `${s}`), ap ]; if (!this.time.a.length) this.time.a = [...this.time.b]; } }
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>js弹力时钟-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号