原生JS實(shí)現(xiàn)非常好看的計(jì)數(shù)器
今天給大家分享一個(gè)用原生JS實(shí)現(xiàn)的好看計(jì)數(shù)器,效果如下:
以下是代碼實(shí)現(xiàn),歡迎大家復(fù)制粘貼和收藏。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>原生JS實(shí)現(xiàn)一個(gè)好看計(jì)數(shù)器</title> <style> * { font-family: '微軟雅黑', sans-serif; box-sizing: border-box; margin: 0; padding: 0; } body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #000d0f; } .container { position: relative; width: 80px; height: 50px; border-radius: 40px; border: 2px solid rgba(255, 255, 255, 0.2); transition: 0.5s; } .container:hover { width: 120px; border: 2px solid rgba(255, 255, 255, 1); } .container .next { position: absolute; top: 50%; right: 30px; display: block; width: 12px; height: 12px; border-top: 2px solid #fff; border-left: 2px solid #fff; z-index: 1; transform: translateY(-50%) rotate(135deg); cursor: pointer; transition: 0.5s; opacity: 0; } .container:hover .next { opacity: 1; right: 20px; } .container .prev { position: absolute; top: 50%; left: 30px; display: block; width: 12px; height: 12px; border-top: 2px solid #fff; border-left: 2px solid #fff; z-index: 1; transform: translateY(-50%) rotate(315deg); cursor: pointer; transition: 0.5s; opacity: 0; } .container:hover .prev { opacity: 1; left: 20px; } #box span { position: absolute; display: none; width: 100%; height: 100%; text-align: center; line-height: 46px; color: #00deff; font-size: 24px; font-weight: 700; user-select: none; } #box span:nth-child(1) { display: initial; } </style> </head> <body> <div class="container"> <div class="next" onclick="nextNum()"></div> <div class="prev" onclick="prevNum()"></div> <div id="box"> <span>0</span> </div> </div> <script> var numbers = document.getElementById('box') for (let i = 0; i < 100; i++) { let span = document.createElement('span') span.textContent = i numbers.appendChild(span) } let num = numbers.getElementsByTagName('span') let index = 0 function nextNum() { num[index].style.display = 'none' index = (index + 1) % num.length num[index].style.display = 'initial' } function prevNum() { num[index].style.display = 'none' index = (index - 1 + num.length) % num.length num[index].style.display = 'initial' } </script> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Cropper.js進(jìn)階實(shí)現(xiàn)圖片旋轉(zhuǎn)裁剪處理功能示例
這篇文章主要為大家介紹了Cropper.js進(jìn)階實(shí)現(xiàn)圖片旋轉(zhuǎn)裁剪功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05讓javascript加載速度倍增的方法(解決JS加載速度慢的問(wèn)題)
這篇文章主要介紹了讓javascript加載速度倍增的方法,通過(guò)document.write輸出js解決廣告加載速度慢的問(wèn)題,需要的朋友可以參考下2014-12-12微信小程序全局配置之tabBar實(shí)戰(zhàn)案例
tabBar相對(duì)而言用的還是比較多的,但是用起來(lái)并沒(méi)有難,下面這篇文章主要給大家介紹了關(guān)于微信小程序全局配置之tabBar的相關(guān)資料,文中通過(guò)圖文以及示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08Javascript中的回調(diào)函數(shù)和匿名函數(shù)的回調(diào)示例介紹
這篇文章主要介紹了Javascript中的回調(diào)函數(shù)和匿名函數(shù)的回調(diào),需要的朋友可以參考下2014-05-05js實(shí)現(xiàn)仿百度風(fēng)云榜可重復(fù)多次調(diào)用的TAB切換選項(xiàng)卡效果
這篇文章主要介紹了js實(shí)現(xiàn)仿百度風(fēng)云榜可重復(fù)多次調(diào)用的TAB切換選項(xiàng)卡效果,涉及javascript鼠標(biāo)事件及頁(yè)面元素遍歷調(diào)用的實(shí)現(xiàn)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08