• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

html弄一个简易时钟

武飞扬头像
Fiskychen
帮助1

新人学习,制作html页面时钟表盘,实现调用时间,

 CSS部分代码如下

  1.  
    html,
  2.  
    body{
  3.  
    background-color: #000000;
  4.  
    }
  5.  
    .fix-center{
  6.  
    position: absolute;
  7.  
    top: 0;
  8.  
    right: 0;
  9.  
    bottom: 0;
  10.  
    left: 0;
  11.  
    margin: auto;
  12.  
    }
  13.  
    /* 风暴烈酒习作 */
  14.  
    .clock-wrapper{
  15.  
    width: 680px;
  16.  
    height: 680px;
  17.  
    background-color: #aa55ff;
  18.  
    border-radius: 50%;
  19.  
    }
  20.  
    .time-wrap{
  21.  
    color: #005500;
  22.  
    font-size: 54px;
  23.  
    font-weight: bold;
  24.  
    }
  25.  
    .dial-time{
  26.  
    position: absolute;
  27.  
    }
  28.  
    .dial-time:nth-child(1){
  29.  
    top: 15px;
  30.  
    left: 50%;
  31.  
    margin-left: -15px;
  32.  
    }
  33.  
    .dial-time:nth-child(2){
  34.  
    right: 40px;
  35.  
    top: 50%;
  36.  
    margin-left: -15px;
  37.  
    }
  38.  
    .dial-time:nth-child(3){
  39.  
    bottom: 15px;
  40.  
    left: 50%;
  41.  
    margin-left: -15px;
  42.  
    }
  43.  
    .dial-time:nth-child(4){
  44.  
    left: 40px;
  45.  
    top: 50%;
  46.  
    margin-left: -15px;
  47.  
    }
  48.  
    .line-wrap{
  49.  
    width: 440px;
  50.  
    height: 27.5rem;
  51.  
    border-radius: 50%;
  52.  
    box-shadow: 0 0 10px 4px #efefef;
  53.  
    }
  54.  
    .dial-line{
  55.  
    position: absolute;
  56.  
    left: 53%;
  57.  
    }
  58.  
    .hour-line{
  59.  
    width:15px;
  60.  
    height: 200px;
  61.  
    margin-top: 80px;
  62.  
    margin-left: -7px;
  63.  
    background-color: #353535;
  64.  
    transform-origin: 50% 75%;
  65.  
    }
  66.  
    .minute-line{
  67.  
    width:10px;
  68.  
    height: 300px;
  69.  
    margin-top: -20px;
  70.  
    margin-left: -5px;
  71.  
    background-color: #353535;
  72.  
    transform-origin: 50% 83%;
  73.  
    }
  74.  
    .second-line{
  75.  
    width:5px;
  76.  
    height: 260px;
  77.  
    margin-top: 20px;
  78.  
    margin-left: -2px;
  79.  
    background-color: red;
  80.  
    transform-origin: 50% 80%;
  81.  
    }
  82.  
    .line-wrap::after{
  83.  
    position: absolute;
  84.  
    top: 1.25rem;
  85.  
    right: 0;
  86.  
    bottom: 0;
  87.  
    left: 27px;
  88.  
    width: 40px;
  89.  
    height: 40px;
  90.  
    margin: auto;
  91.  
    background-color: #ff0000;
  92.  
    border-radius: 50%;
  93.  
    content: '';
  94.  
    }
  95.  
     
  96.  
     
  97.  
     
  98.  
     
  99.  
     
  100.  
     
  101.  
     
  102.  
     
  103.  
     
学新通

javascript部分代码如下: 

  1.  
    /* 表盘指针 */
  2.  
    let hourLine = document.querySelector('.hour-line'),
  3.  
    minuteLine = document.querySelector('.minute-line'),
  4.  
    secondLine = document.querySelector('.second-line');
  5.  
     
  6.  
    function setTime(){
  7.  
    const date = new Date();
  8.  
    let s = date.getSeconds(),
  9.  
    m = date.getMinutes() s / 60,
  10.  
    h = date.getHours() m / 60;
  11.  
    /* 风暴烈酒习作 */
  12.  
    hourLine.style.transform = `rotate(${h*30}deg)`;
  13.  
    minuteLine.style.transform = `rotate(${m*6}deg)`;
  14.  
    secondLine.style.transform = `rotate(${s*6}deg)`;
  15.  
    }
  16.  
    setTime();
  17.  
    setInterval(setTime,1000);
学新通

 HMTL部分代码如下:

  1.  
    <!DOCTYPE html>
  2.  
    <html lang="en">
  3.  
    <!-- 陈.风暴烈酒学习制作 -->
  4.  
    <head>
  5.  
    <meta charset="utf-8" />
  6.  
    <meta http-equiv='X-UA-Compatible' content="IE=edge,chrome=1">
  7.  
    <meta name="viewport" content="width=device-width,initial-scale=1.0" >
  8.  
    <title>document</title>
  9.  
    <link rel="stylesheet" href="css/index.css">
  10.  
    </head>
  11.  
    <body>
  12.  
    <div class="clock-wrapper fix-center">
  13.  
    <!-- 表盘数字 -->
  14.  
    <div class="time-wrap">
  15.  
    <div class="dial-time">12</div>
  16.  
    <div class="dial-time">3</div>
  17.  
    <div class="dial-time">6</div>
  18.  
    <div class="dial-time">9</div>
  19.  
    </div>
  20.  
     
  21.  
    </div>
  22.  
    <!-- 表盘指针 -->
  23.  
    <div class="line-wrap fix-center">
  24.  
    <div class="dial-line hour-line"></div>
  25.  
    <div class="dial-line minute-line"></div>
  26.  
    <div class="dial-line second-line"></div>
  27.  
     
  28.  
    </div>
  29.  
    <script src='js/index1.js' type="text/javascript" charset="utf-8"></script>
  30.  
    </body>
  31.  
    </html>
学新通

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgffabe
系列文章
更多 icon
同类精品
更多 icon
继续加载