• 画一个时钟(html+css+js)


    这是一个很简约的时钟。。。。。。。

    效果:

    代码: 

    1. <script setup>
    2. import {onMounted, computed} from 'vue';
    3. let timer = null
    4. const rotatedAngles = computed(() => {
    5. return Array.from({length: 60}, (_, index) => index * 6);
    6. })
    7. const startTime = () => {
    8. const min = document.getElementById('min')
    9. const sec = document.getElementById('sec')
    10. const hour = document.getElementById('hour')
    11. const now = new Date()
    12. const s = now.getSeconds()
    13. const then = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)
    14. const diffInMil = now.getTime() - then.getTime()
    15. const h = diffInMil / (1000 * 60 * 60)
    16. const m = h * 60;
    17. if (hour || min || sec) {
    18. hour.style.transform = `rotate(${h * 30}deg)`;
    19. min.style.transform = `rotate(${m * 6}deg)`;
    20. sec.style.transform = `rotate(${s * 6}deg)`;
    21. }
    22. }
    23. onMounted(() => {
    24. startTime()
    25. timer = setInterval(() => {
    26. setTimeout(startTime, 0)
    27. }, 1000)
    28. })
    29. script>
    30. <style scoped lang="scss">
    31. .demo-box {
    32. width: 800px;
    33. margin: 100px auto;
    34. }
    35. ul li {
    36. list-style: none;
    37. }
    38. @mixin center {
    39. position: absolute;
    40. top: 0;
    41. left: 0;
    42. right: 0;
    43. bottom: 0;
    44. margin: auto;
    45. }
    46. .clock {
    47. width: 180px;
    48. height: 180px;
    49. position: relative;
    50. }
    51. .mark {
    52. width: 180px;
    53. height: 180px;
    54. position: relative;
    55. }
    56. //画刻度尺
    57. .mark li {
    58. position: absolute;
    59. width: 6px;
    60. height: 2px;
    61. background: #666;
    62. border-radius: 1px;
    63. transform-origin: 90px;
    64. }
    65. .mark li.bold {
    66. width: 12px;
    67. height: 4px;
    68. margin-top: -1px;
    69. background: #000;
    70. border-radius: 2px;
    71. }
    72. #sec {
    73. //中心圆点
    74. @include center;
    75. background: #303030;
    76. width: 10px;
    77. height: 10px;
    78. border-radius: 50%;
    79. z-index: 3;
    80. &:before,
    81. &:after {
    82. display: block;
    83. content: "";
    84. position: absolute;
    85. }
    86. //秒针
    87. &:after {
    88. width: 2px;
    89. height: 4.4em;
    90. top: -4.3em;
    91. background: #303030;
    92. left: 0;
    93. right: 0;
    94. margin: 0 auto;
    95. border-radius: 1px;
    96. }
    97. }
    98. #min,
    99. #hour {
    100. @include center;
    101. z-index: 2;
    102. background: #303030;
    103. transform-origin: bottom center;
    104. }
    105. //分针
    106. #min {
    107. width: 4px;
    108. height: 4.2em;
    109. top: -4.2em;
    110. border-radius: 4px;
    111. }
    112. //时针
    113. #hour {
    114. width: 4px;
    115. height: 3em;
    116. top: -3em;
    117. border-radius: 4px;
    118. }
    119. style>

  • 相关阅读:
    AI毕业论文降重GPTS,避免AI检测,高效完成论文
    centos部署tomcat
    SQL教程之性能不仅仅是查询
    Hadoop Namenode节点迁移
    Linux内核中断机制
    pandas数据离散化
    redis-集群-2-哨兵模式
    内网配置git代理
    TCP/IP网络协议详解
    Util应用框架核心(二) - 启动器
  • 原文地址:https://blog.csdn.net/csdnyp/article/details/133172413