css3和js實現的圓形鐘錶效果程式碼例項
分享一段程式碼例項,它利用css和js實現了圓形鐘錶效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style id="css"> #box{ width:200px; height:200px; border:4px solid #000; margin:30px auto; border-radius:50%; position:relative; } #list{ margin:0; padding:0; list-style:none; width:200px; height:200px; position:relative; } #list li{ width:2px; height:6px; background:#000; position:absolute; top:0; left:99px; transform-origin:center 100px; } #list li:nth-of-type(5n+1){ height:15px; } #hours{ width:8px; height:45px; background:#000; position:absolute; left:96px; top:55px; transform-origin:bottom; } #min{ width:4px; height:60px; background:#066; position:absolute; left:98px; top:40px; transform-origin:bottom; } #sec{ width:2px; height:80px; background:red; position:absolute; left:99px; top:20px; transform-origin:bottom; } .ico{ width:20px; height:20px; background:#000; border-radius:50%; position:absolute; left:90px; top:90px; } </style> <script> window.onload = function() { var oList = document.getElementById("list"); var oCss = document.getElementById("css"); var sHtml = "", sCss = ""; var oHours = document.getElementById("hours"); var oMin = document.getElementById("min"); var oSec = document.getElementById("sec"); for (var i = 0; i < 60; i++) { sHtml += "<li></li>"; sCss += "#list li:nth-of-type(" + (i + 1) + "){ transform:rotate(" + (i * 6) + "deg);}"; } oList.innerHTML = sHtml; oCss.innerHTML += sCss; toDate(); setInterval(toDate, 1000); function toDate() { var oDate = new Date(); var iSec = oDate.getSeconds(); var iMin = oDate.getMinutes() + iSec / 60; var iHours = oDate.getHours() + iMin / 60; oSec.style.transform = "rotate(" + iSec * 6 + "deg)"; oMin.style.transform = "rotate(" + iMin * 6 + "deg)"; oHours.style.transform = "rotate(" + iHours * 30 + "deg)"; } }; </script> </head> <body> <div id="box"> <ul id="list"></ul> <div id="hours"></div> <div id="min"></div> <div id="sec"></div> <div class="ico"></div> </div> </body> </html>
相關文章
- canvas實現的圓形鐘錶效果程式碼例項Canvas
- js和css3實現的圓形鐘錶效果JSCSSS3
- javascript圓形電子鐘錶效果程式碼例項JavaScript
- javascript圓形鐘錶程式碼例項JavaScript
- jquery自動走動的圓形鐘錶效果程式碼例項jQuery
- js鐘錶效果程式碼例項JS
- jquery和css實現的圓形鐘錶效果jQueryCSS
- css實現圓形、橢圓和半圓效果程式碼例項CSS
- canvas繪製圓形鐘錶程式碼例項Canvas
- css3動態圓形鐘錶效果CSSS3
- css3實現的圓角效果程式碼例項CSSS3
- canvas實現的圓形走動鐘錶效果Canvas
- CSS3圓形時鐘效果程式碼CSSS3
- CSS3 實現的鐘表效果程式碼例項CSSS3
- CSS3實現的div圓角效果程式碼例項CSSS3
- SVG圓形鐘錶效果SVG
- JavaScript圓形鐘錶效果JavaScript
- canvas原型鐘錶效果程式碼例項Canvas原型
- css3橢圓形程式碼例項CSSS3
- js秒錶效果程式碼例項JS
- canvas繪製鐘錶效果程式碼例項Canvas
- CSS3心形效果程式碼例項CSSS3
- canvas實現的鐘表效果程式碼例項Canvas
- canvas實現的圓形時鐘效果Canvas
- css3實現的折角效果程式碼例項CSSS3
- CSS3梯形效果程式碼例項CSSS3
- jQuery和css3實現的開關效果程式碼例項jQueryCSSS3
- css3實現的打折卡效果程式碼例項CSSS3
- css3實現的毛玻璃效果程式碼例項CSSS3
- css3實現的打字機效果程式碼例項CSSS3
- css3實現的氣泡效果程式碼例項CSSS3
- JavaScript動態圓形鐘錶效果詳解JavaScript
- css3實現的三角形對插效果程式碼例項CSSS3
- CSS3實現的環形旋轉載入補全效果程式碼例項CSSS3
- js圓形環繞運動程式碼例項JS
- CSS3實現的平行四邊形程式碼例項CSSS3
- canvas實現的動態心形效果程式碼例項Canvas
- css3實現的文字下滑出現效果程式碼例項CSSS3