前言:

分享一个好玩的小组件,滚动数字时钟效果。

实现效果:

实现源码:新建一个vue文件,把下面内容都放进去,运行就好了

<template><div class="wraper"><div class="column" :style="{transform: `translateY(${-lineHeight*index6}px)`}"><div class="num" v-for="(item, index) in arr6" :key="index">{{ item }}</div></div><div class="column" :style="{transform: `translateY(${-lineHeight*index5}px)`}"><div class="num" v-for="(item, index) in arr5" :key="index">{{ item }}</div></div><div>:</div><div class="column" :style="{transform: `translateY(${-lineHeight*index4}px)`}"><div class="num" v-for="(item, index) in arr4" :key="index">{{ item }}</div></div><div class="column" :style="{transform: `translateY(${-lineHeight*index3}px)`}"><div class="num" v-for="(item, index) in arr3" :key="index">{{ item }}</div></div><div>:</div><div class="column" :style="{transform: `translateY(${-lineHeight*index2}px)`}"><div class="num" v-for="(item, index) in arr2" :key="index">{{ item }}</div></div><div class="column" :style="{transform: `translateY(${-lineHeight*index1}px)`}"><div class="num" v-for="(item, index) in arr1" :key="index">{{ item }}</div></div></div>
</template><script>export default {data() {return {lineHeight: 64, //跟字体大小和wraper的高度相关!// 秒arr1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],index1: 0, //就是获取真实时间后的起始数字arr2: [0, 1, 2, 3, 4, 5],index2: 0,// 分arr3: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],index3: 0,arr4: [0, 1, 2, 3, 4, 5],index4: 0,// 时arr5: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],index5: 0,arr6: [0, 1, 2],index6: 0,}},created() {this.getTime()},watch: {index5(newVal) {// 超过24小时if (this.index6 === 2 && newVal===4) {console.log('out')for (let i=1; i<7; i++) {this[`index${i}`] = 0}}}},methods: {getTime() {const date = new Date()let hour = this.bu0(date.getHours())let minute = this.bu0(date.getMinutes())let second = this.bu0(date.getSeconds())// 测试用// let hour = ['1', '9']// let minute = ['5', '9']// let second = ['5', '5']// 秒this.index1 = +second[1]this.index2 = +second[0]// 分this.index3 = +minute[1]this.index4 = +minute[0]// 时this.index5 = +hour[1]this.index6 = +hour[0]this.turnSecond(this.arr1.length)},bu0(num) {let strif (num < 10) str = `0${num}`else str = `${num}`return str.split('')},turnSecond (length) {setInterval(()=> {if (this.index1 === length-1) {// console.log(1)// 通知前一位移动this.turnOther( 2, this.arr2.length)this.index1 = -1}this.index1++}, 1000)},turnOther(type, length) {// type代表第几组数列,例如2,就是从右往左第二列if (this[`index${type}`] === length-1) {// console.log(type)// 通知前一位移动let next = type+1this.turnOther( next, this[`arr${next}`].length)this[`index${type}`] = -1}this[`index${type}`]++}}}
</script><style scoped>.wraper {text-align: center;background: #ffffff;height: 64px;font-size: 48px;font-weight: bolder;letter-spacing: 7px;margin-top: 7px;display: flex;justify-content: center;overflow:hidden;}.column {transition: transform 300ms;}.num {height: 64px;}
</style>

vue2中实现滚动数字时钟效果相关推荐

  1. js选中html的数字设置倒计时,JS实现的网页倒计时数字时钟效果

    本文实例讲述了JS实现的网页倒计时数字时钟效果.分享给大家供大家参考.具体实现方法如下: 代码如下: javascript实现的倒计时时钟 body,div{margin:0;padding:0;} ...

  2. 数字时钟html脚本,javascript实现数字时钟效果

    本文实例为大家分享了javascript实现数字时钟效果的具体代码,供大家参考,具体内容如下 效果图 需求分析 1.通过date获取时间 2.通过间隔定时器setInterval动态获取时间 3.间隔 ...

  3. js滚动数字动画效果

    代码复制,直接调用就好了. 需注意!由于js不能精确到小数点后的0,(9.90)在JS中为9.9,所以不能用在有小数点的场景下,只能用在整数的情况下 /*** 滚动数字* @param {*DOM} ...

  4. Vue3中如何实现数字翻牌效果?

    一.需求 监听数据的变化,实现数字翻牌效果 本人OS:本想截一个gif,但是一直没找到合适的截gif工具......有好用的截gif工具,跪求戳戳我~ 二.思路 1.设置初始数组:[0] 2. 把获取 ...

  5. 前端用vue实现一个滚动数字时钟

    效果如图所示 如果想直接用可以复制代码当作vue组件. 实现原理 时钟实际上是六个独立的纵向数列,每列的数字从下往上滚动,秒数滚动到头就向左"进一位",每一列到头都会向左" ...

  6. FPGA数字时钟(可暂停调数,含代码)

    前言 前段时间刚刚开始初步学习FPGA相关知识,在学习了一段时间后,利用前面所学知识,写了一个数字时钟,顺便在这里写下总结,方便理解. (本人小白一名,有错欢迎指出,欢迎探讨) (我使用的开发板是Cy ...

  7. arduino定时器pdf_Arduino基础入门篇18—数字时钟

    Arduino不但有外部中断,还有定时器中断,不同Arduino开发板其定时器数量及性能也各不相同,这取决于开发板主控制器.Uno R3开发板有三个定时器,本篇通过使用定时器库「TimerOne」来更 ...

  8. Android开发——实现数字时钟

    前言 在最近的项目当中,我遇到一个在界面中实现系统数字时钟的需求.一看这个其实挺简单的,开个一个子线程获取当前的系统时间睡眠1分钟发送当前时间,然后利用Handler去修改当前显示的时间,直接撸代码. ...

  9. Timer实现数字时钟

    最近在做一个GPS的应用,其中界面使用Fragment实现切换.其中一个Fragment中实现了数字时钟,即每一秒就更新数字显示那种~~ 结果在切换Fragment时,出现了下面的错误: 01-23 ...

最新文章

  1. VC6中用DOM遍历网页中的元素
  2. Spring Boot配置多数据源
  3. html 正方形缩略图,html – 纯CSS图像缩略图
  4. 闭包和高阶函数-函数式编程的基本特征
  5. android xml 指纹动画,Android 指纹识别(给应用添加指纹解锁)
  6. 开发组2007年3月开发计划
  7. c#简单注册登录利用缓存存储账号密码_“密码代填”实现单点登录,安全吗?...
  8. 郑州市城市建成区20年时空变化特征提取与分析
  9. rbf神经网络参数设置_基于梯度下降法的RBF神经网络(04)
  10. 2016 yyuc框架环境配置
  11. diy的电流电压表,高频率采集,上位机同步显示
  12. 现代控制理论(5)——线性定常系统的综合
  13. 解决Steam首次安装更新缓慢 过慢 无反应的问题
  14. 软件测试师和网络工程师,【软件测试工程师(科技部)网络工程师面试题目|面试经验】-看准网...
  15. 使用Python合并excel表格的两列
  16. 合伙创业 三大误区
  17. 依分布收敛、依概率收敛、均方收敛、几乎处处收敛
  18. FX5U MODBUS_TCP通讯
  19. win7计算机高级设置在哪,windows7投屏设置在哪里
  20. 基于单片机的温度控制系统

热门文章

  1. JAVA开发微信 AIRKISS 一键WIFI功能(测试账户)
  2. ROBLOX十字路口红绿灯系统(行人和车辆AI)
  3. 大华sdk转springboot项目 (刷卡、刷人脸、刷二维码、刷身份证)
  4. windows无法连接到打印机 错误代码为0x00000533,解决办法
  5. 英文文献 安全 计算机,文献综述-中英文文献翻译-计算机数控机床的安全和维护...
  6. Swagger 2(Open API v3.0) Java 文档生成指南(下)
  7. 高中计算机手抄报图片大全集,高中科技节手抄报图片大全
  8. 如何用python获取通达信数据_Python读取通达信本地数据
  9. Introduction to the zSpace Platform(zSpace平台介绍)
  10. 汇编语言学习详细笔记