类似于图片这种效果,总共24个刻度。
某个时间段有会议,则显示图片中橙色部分的样式。
每场会议以30分钟为基本单位。
请各位大佬指教
使用Canvas可以实现该表盘,做个固定的背景图就行了,我给你个demo
你改 ctx.arc(200, 200, 170, convertNum(0), convertNum(3));
后面两个参数就能实现几点到几点了
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<style>
body {
background-color: gray;
}
h1 {
font-family: helvetica;
font-size: 2.5rem;
color: black;
position: relative;
top: 80px;
z-index: -1;
}
#canvas {
display: block;
margin: 5vh auto;
border-radius: 50%;
box-shadow: 0 5px 14px black;
}
</style>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
</body>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.strokeStyle = "#e44b24";
ctx.lineWidth = 17;
ctx.lineCap = "round";
// ctx.shadowBlur = 15;
// ctx.shadowColor = '#28d1fa';
function degToRad(degree) {
var factor = Math.PI / 180;
return degree * factor;
}
// 转换数值 360度转换成24份,并修正从0点开始
function convertNum(num) {
return degToRad(num * 15 - 90);
}
function draw() {
var now = new Date();
var today = now.toDateString();
var time = now.toLocaleTimeString();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var milliseconds = now.getMilliseconds();
var newSeconds = seconds + milliseconds / 1000;
// Background
gradient = ctx.createRadialGradient(200, 200, 5, 200, 200, 300);
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 400, 400);
// 0点到3点
ctx.beginPath();
ctx.arc(200, 200, 170, convertNum(0), convertNum(3));
ctx.stroke();
// 7到8
ctx.beginPath();
ctx.arc(200, 200, 170, convertNum(7), convertNum(8));
ctx.stroke();
// 14-16
ctx.beginPath();
ctx.arc(200, 200, 170, convertNum(14), convertNum(16));
ctx.stroke();
}
draw();
</script>
</html>
8 回答5.8k 阅读✓ 已解决
9 回答9.2k 阅读
6 回答4.7k 阅读✓ 已解决
3 回答10.3k 阅读✓ 已解决
4 回答7.2k 阅读
5 回答7.1k 阅读✓ 已解决
5 回答8.2k 阅读
用
svg
,path
绘制圆弧: