当前位置: 首页 > news >正文

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

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

效果:

代码: 

<template><div class="demo-box"><div class="clock"><ul class="mark"><liv-for="(rotate, index) in rotatedAngles":key="index":class="{ 'bold': index % 5 === 0 }":style="{ transform: `translateY(90px) rotate(${rotate}deg)` }"></li></ul><div id="min"></div><div id="hour"></div><div id="sec"></div></div></div>
</template><script setup>
import {onMounted, computed} from 'vue';let timer = nullconst rotatedAngles = computed(() => {return Array.from({length: 60}, (_, index) => index * 6);
})const startTime = () => {const min = document.getElementById('min')const sec = document.getElementById('sec')const hour = document.getElementById('hour')const now = new Date()const s = now.getSeconds()const then = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)const diffInMil = now.getTime() - then.getTime()const h = diffInMil / (1000 * 60 * 60)const m = h * 60;if (hour || min || sec) {hour.style.transform = `rotate(${h * 30}deg)`;min.style.transform = `rotate(${m * 6}deg)`;sec.style.transform = `rotate(${s * 6}deg)`;}
}onMounted(() => {startTime()timer = setInterval(() => {setTimeout(startTime, 0)}, 1000)
})</script><style scoped lang="scss">
.demo-box {width: 800px;margin: 100px auto;
}ul li {list-style: none;
}@mixin center {position: absolute;top: 0;left: 0;right: 0;bottom: 0;margin: auto;
}.clock {width: 180px;height: 180px;position: relative;
}.mark {width: 180px;height: 180px;position: relative;
}//画刻度尺
.mark li {position: absolute;width: 6px;height: 2px;background: #666;border-radius: 1px;transform-origin: 90px;
}.mark li.bold {width: 12px;height: 4px;margin-top: -1px;background: #000;border-radius: 2px;
}#sec {//中心圆点@include center;background: #303030;width: 10px;height: 10px;border-radius: 50%;z-index: 3;&:before,&:after {display: block;content: "";position: absolute;}//秒针&:after {width: 2px;height: 4.4em;top: -4.3em;background: #303030;left: 0;right: 0;margin: 0 auto;border-radius: 1px;}
}#min,
#hour {@include center;z-index: 2;background: #303030;transform-origin: bottom center;
}//分针
#min {width: 4px;height: 4.2em;top: -4.2em;border-radius: 4px;
}//时针
#hour {width: 4px;height: 3em;top: -3em;border-radius: 4px;
}
</style>

http://www.lryc.cn/news/172673.html

相关文章:

  • 红 黑 树
  • 掷骰子的多线程应用程序1(复现《Qt C++6.0》)
  • 【vue2第十八章】VueRouter 路由嵌套 与 keep-alive缓存组件(activated,deactivated)
  • 如何确保亚马逊、速卖通等平台测评补单的环境稳定性和安全性?
  • echarts图表 实现高度按照 内容撑起来或者超出部分滚动展示效果
  • 【论文阅读】检索增强发展历程及相关文章总结
  • 【漏洞复现系列】二、weblogic-cve_2020_2883(RCE/反序列化)
  • 算法通关村-----LRU的设计与实现
  • 王江涛十天搞定考研词汇
  • 算法(二)——数组章节和链表章节
  • Android:ListView在Fragment中的使用
  • BIGEMAP在土地规划中的应用
  • 软件测试常见术语和名词解释
  • prometheus+process_exporter进程监控
  • 四川玖璨电子商务有限公司专注抖音电商运营
  • python LeetCode 刷题记录 83
  • Grom 如何解决 SQL 注入问题
  • 腾讯mini项目-【指标监控服务重构】2023-07-19
  • 抖音矩阵系统源代码开发部署--SaaS开源技术开发文档
  • CLIP模型资料学习
  • 【c语言】贪吃蛇
  • 【Node.js】定时任务cron:
  • vue3 引入element-plus
  • 数据通信——传输层TCP(超时时间选择)
  • 【数据库索引优化】
  • WebGL 选中物体
  • 科目二倒车入库
  • PostgreSQL如何支持PL/Python过程语言
  • 【C++】STL之适配器---用deque实现栈和队列
  • PHY6230低成本遥控灯控芯片国产蓝牙BLE5.2 2.4G SoC