• 用vue写一个炫酷的数字时钟


    灵感来源

    codepen上看到一个大佬的作品,比较有意思,就想用vue写一个更简单的。代码很简单。

    gif演示图片加载缓慢,可以点击这里可以查看代码运行效果
    digital-clock

    全部代码

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="UTF-8" />
      <title>数字时钟</title>
      <script src="https://lib.baomitu.com/vue/2.6.14/vue.min.js"></script>
      <style>
        :root {
          --numberSize: 40px;
          --clockColor: blueviolet;
        }
    
        * {
          margin: 0;
          padding: 0;
        }
    
        ul,
        li {
          list-style: none;
        }
    
        body {
          min-height: 100vh;
          display: flex;
          justify-content: center;
          align-items: center;
        }
    
        #app {
          position: relative;
          margin-top: 400px;
          display: flex;
        }
    
        #app::before,
        #app::after {
          position: absolute;
          top: 13px;
          right: 102px;
          content: '';
          display: block;
           4px;
          height: 4px;
          box-shadow: 0px 10px 0px 0px var(--clockColor);
          background-color: var(--clockColor);
        }
    
        #app::before {
          left: 86px;
        }
    
        .strip {
          height: fit-content;
          margin: 0 5px;
          border-radius: 4px;
          background-color: #99CCFF;
          transition: .5s;
        }
    
        .strip:nth-of-type(2n) {
          margin-right: 20px;
        }
    
        .number {
           calc(var(--numberSize) - 10px);
          height: var(--numberSize);
          line-height: var(--numberSize);
          color: #fff;
          text-align: center;
        }
    
        .number.active {
          color: var(--clockColor);
          font-size: 20px;
          font-weight: bold;
          transition: .5s;
        }
      </style>
    </head>
    
    <body>
      <div id="app">
        <ul 
          v-for="(strip, index) in stripArr"
          :key="index"
          class="strip"
          :style="{transform: `translateY(${-timeArr[index] * 40}px)`}">
          <li 
            v-for="num in strip"
            :key="num"
            class="number"
            :class="{active: timeArr[index] === num - 1}">
            {{num-1}}
          </li>
        </ul>
      </div>
    </body>
    
    <script type="text/javascript">
      Vue.config.productionTip = false
      new Vue({
        el: '#app',
        data: {
          stripArr: [3, 10, 6, 10, 6, 10],
          timeArr: [0, 0, 0, 0, 0, 0]
        },
        mounted() {
          setInterval(() => {
            const time = new Date()
            const h = time.getHours().toString().padStart(2, '0')
            const m = time.getMinutes().toString().padStart(2, '0')
            const s = time.getSeconds().toString().padStart(2, '0')
            this.timeArr = (h + m + s).split('').map(Number)
          }, 1000)
        }
      })
    </script>
    
    </html>
    
  • 相关阅读:
    566. Reshape the Matrix矩阵重排
    697. Degree of an Array 频率最高元素的最小覆盖子数组
    717. 1-bit and 2-bit Characters最后一位数是否为0
    189. Rotate Array 从右边开始翻转数组
    448. Find All Numbers Disappeared in an Array 寻找有界数组[1,n]中的缺失数
    268. Missing Number序列中遗失的数字
    C 练习实例20 – 小球自由下落
    menu (Elements) – HTML 中文开发手册
    HTML DOM Password form 属性
    fmal (Numerics) – C 中文开发手册
  • 原文地址:https://www.cnblogs.com/lwlblog/p/15905715.html
Copyright © 2020-2023  润新知