• vue2中实现滚动数字时钟效果


    前言:

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

    实现效果:

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

    1. <script>
    2. export default {
    3. data() {
    4. return {
    5. lineHeight: 64, //跟字体大小和wraper的高度相关!
    6. // 秒
    7. arr1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
    8. index1: 0, //就是获取真实时间后的起始数字
    9. arr2: [0, 1, 2, 3, 4, 5],
    10. index2: 0,
    11. // 分
    12. arr3: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
    13. index3: 0,
    14. arr4: [0, 1, 2, 3, 4, 5],
    15. index4: 0,
    16. // 时
    17. arr5: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
    18. index5: 0,
    19. arr6: [0, 1, 2],
    20. index6: 0,
    21. }
    22. },
    23. created() {
    24. this.getTime()
    25. },
    26. watch: {
    27. index5(newVal) {
    28. // 超过24小时
    29. if (this.index6 === 2 && newVal===4) {
    30. console.log('out')
    31. for (let i=1; i<7; i++) {
    32. this[`index${i}`] = 0
    33. }
    34. }
    35. }
    36. },
    37. methods: {
    38. getTime() {
    39. const date = new Date()
    40. let hour = this.bu0(date.getHours())
    41. let minute = this.bu0(date.getMinutes())
    42. let second = this.bu0(date.getSeconds())
    43. // 测试用
    44. // let hour = ['1', '9']
    45. // let minute = ['5', '9']
    46. // let second = ['5', '5']
    47. // 秒
    48. this.index1 = +second[1]
    49. this.index2 = +second[0]
    50. // 分
    51. this.index3 = +minute[1]
    52. this.index4 = +minute[0]
    53. // 时
    54. this.index5 = +hour[1]
    55. this.index6 = +hour[0]
    56. this.turnSecond(this.arr1.length)
    57. },
    58. bu0(num) {
    59. let str
    60. if (num < 10) str = `0${num}`
    61. else str = `${num}`
    62. return str.split('')
    63. },
    64. turnSecond (length) {
    65. setInterval(()=> {
    66. if (this.index1 === length-1) {
    67. // console.log(1)
    68. // 通知前一位移动
    69. this.turnOther( 2, this.arr2.length)
    70. this.index1 = -1
    71. }
    72. this.index1++
    73. }, 1000)
    74. },
    75. turnOther(type, length) {
    76. // type代表第几组数列,例如2,就是从右往左第二列
    77. if (this[`index${type}`] === length-1) {
    78. // console.log(type)
    79. // 通知前一位移动
    80. let next = type+1
    81. this.turnOther( next, this[`arr${next}`].length)
    82. this[`index${type}`] = -1
    83. }
    84. this[`index${type}`]++
    85. }
    86. }
    87. }
    88. script>
    89. <style scoped>
    90. .wraper {
    91. text-align: center;
    92. background: #ffffff;
    93. height: 64px;
    94. font-size: 48px;
    95. font-weight: bolder;
    96. letter-spacing: 7px;
    97. margin-top: 7px;
    98. display: flex;
    99. justify-content: center;
    100. overflow:hidden;
    101. }
    102. .column {
    103. transition: transform 300ms;
    104. }
    105. .num {
    106. height: 64px;
    107. }
    108. style>

  • 相关阅读:
    Win7批量执行Python文件
    .NET现代应用的产品设计 - DDD实践
    JavaIO之read()和readline
    网络基础1
    【树莓派不吃灰】命令篇⑥ 了解树莓派Boot分区,学习Linux启动流程
    数学建模经验分享会For浙商大管工学院
    【分类网络】VGG
    一本专业130+总分400+上海交通大学819考研经验上交电子信息与通信工程上岸,真题,大纲,参考书。
    ChatGPT DALL-E 3的系统提示词大全
    (附源码)ssm在线点餐系统 毕业设计 111016
  • 原文地址:https://blog.csdn.net/qq_41619796/article/details/127860403