国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

原生JS實現的簡單小鐘表功能示例

2019-11-19 13:06:49
字體:
來源:轉載
供稿:網友

本文實例講述了原生JS實現的簡單小鐘表功能。分享給大家供大家參考,具體如下:

先來看看運行效果:

完整代碼:

<!DOCTYPE html><html>  <head>    <meta charset="UTF-8">    <title>www.survivalescaperooms.com 鐘表</title>    <style type="text/css">      body {       background-color:#00A2D4;      }      .clock {        width: 200px;        height: 200px;        background: -webkit-radial-gradient(#3b3b3b, #000);        background: radial-gradient(#2E3F50, #0E1B29);        box-shadow: inset 0px 0px 30px #131313, 0px 2px 18px rgba(0,0,0,0.5);        border: 6px solid #172839;        border-radius: 106px;        margin: auto;        position: absolute;        top: 0; bottom: 0; left: 0; right: 0;      }      .hour-hand {        width: 4px;        height: 55px;        background: #fff;        box-shadow: 0px 0px 7px #000;        position: absolute;        top: 45px;        left: 98px;      }      .minute-hand {        width: 4px;        height: 80px;        background: #fff;        box-shadow: 0px 0px 4px #000;        position: absolute;        top: 20px;        left: 98px;      }      .second-hand {        width: 2px;        height: 80px;        background: #bbb;        box-shadow: 0px 0px 7px #000;        position: absolute;        top: 20px;        left: 99px;      }      .pin {        width: 10px;        height: 10px;        background: #222;        border-radius: 10px;        margin: auto;        position: absolute;        top: 0; bottom: 0; left: 0; right: 0;      }      .hour-hand,      .minute-hand,      .second-hand {        -webkit-transform-origin: 50% 100%;        -moz-transform-origin: 50% 100%;        -o-transform-origin: 50% 100%;        -ms-transform-origin: 50% 100%;        transform-origin: 50% 100%;      }      .circle{        width:20px;        height:20px;        line-height:20px;        text-align:center;        color:#fff;        position: absolute;      }    </style>  </head>  <body>    <div class="clock">      <div class="minute-hand"></div>      <div class="hour-hand"></div>      <div class="second-hand"></div>      <div class="pin"></div>      <div class="circle">6</div>      <div class="circle">5</div>      <div class="circle">4</div>      <div class="circle">3</div>      <div class="circle">2</div>      <div class="circle">1</div>      <div class="circle">12</div>      <div class="circle">11</div>      <div class="circle">10</div>      <div class="circle">9</div>      <div class="circle">8</div>      <div class="circle">7</div>    </div>    <div class="time"></div>    <script type="text/javascript">      window.onload=function(){        setInterval(function(){          var dt = new Date();          var sec_deg = dt.getSeconds() * (360/60);          var min_deg = dt.getMinutes() * (360/60);          var hr_deg = dt.getHours() * (360/12) + dt.getMinutes() * (360/60/12);          document.querySelector(".clock .second-hand").style.cssText='-webkit-transform:rotate(' + sec_deg + 'deg)','-moz-transform:rotate(' + sec_deg + 'deg)', '-o-transform:rotate(' + sec_deg + 'deg)', '-ms-transform:rotate(' + sec_deg + 'deg)', 'transform:rotate(' + sec_deg + 'deg)';          document.querySelector('.clock .minute-hand').style.cssText='-webkit-transform:rotate(' + min_deg + 'deg)', '-moz-transform:rotate(' + min_deg + 'deg)', '-o-transform:rotate(' + min_deg + 'deg)', '-ms-transform:rotate(' + min_deg + 'deg)', 'transform:rotate(' + min_deg + 'deg)';          document.querySelector('.clock .hour-hand').style.cssText='-webkit-transform:rotate(' + hr_deg + 'deg)', '-moz-transform:rotate(' + hr_deg + 'deg)', '-o-transform:rotate(' + hr_deg + 'deg)', '-ms-transform:rotate(' + hr_deg + 'deg)', 'transform:rotate(' + hr_deg + 'deg)';         }, 1000);        var dx=90,          dy=90,          s=87,//半徑          x=Math.sin(0),          y=Math.cos(0),          dig=2*Math.PI/12;        var circle=document.querySelectorAll(".circle");        for(var i=0;i<12;i++){          var x=Math.sin(i*dig);          var y=Math.cos(i*dig);          var topValue=Number(dy+y*s),            leftValue=Number(dx+x*s);          circle[i].style.top=topValue+"px";          circle[i].style.left=leftValue+"px";        }      }    </script>  </body></html>

感興趣的朋友可使用在線HTML/CSS/JavaScript代碼運行工具http://tools.VeVB.COm/code/HtmlJsRun測試一下運行效果。

PS:這里再為大家推薦幾款時間及日期相關工具供大家參考使用:

在線日期/天數計算器:
http://tools.VeVB.COm/jisuanqi/date_jisuanqi

在線日期計算器/相差天數計算器:
http://tools.VeVB.COm/jisuanqi/datecalc

在線日期天數差計算器:
http://tools.VeVB.COm/jisuanqi/onlinedatejsq

Unix時間戳(timestamp)轉換工具:
http://tools.VeVB.COm/code/unixtime

更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript時間與日期操作技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript錯誤與調試技巧總結》、《JavaScript數據結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數學運算用法總結

希望本文所述對大家JavaScript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 双牌县| 淳化县| 武城县| 炉霍县| 株洲县| 湖州市| 金塔县| 封丘县| 仙桃市| 建阳市| 宜宾县| 黄龙县| 石狮市| 卓尼县| 萝北县| 全椒县| 彰武县| 汽车| 杂多县| 湘西| 蒙山县| 宾阳县| 龙山县| 隆德县| 东阿县| 文登市| 陇川县| 延吉市| 阿克| 台东市| 青河县| 乌兰浩特市| 长沙市| 云安县| 分宜县| 徐水县| 清水县| 呼和浩特市| 环江| 油尖旺区| 嘉鱼县|