js+svg实现数字时钟显示时间效果代码

代码语言:html

所属分类:其他

代码描述:js+svg实现数字时钟显示时间效果代码

代码标签: js svg 数字 时钟 显示 时间

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  
  
  
<style>
body {
	background: #111;
}
#clock {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: calc(100vw - 4px);
	max-width: 300px;
}
</style>



  
  
</head>

<body>
  <div id="clock"></div>

      <script>
// this function creates the SVG and appends it to the element you give to it
function initClock(elt, color = '#0ff', backgroundColor = 'none') {
	let timeObj = {
		numberPathsD: {
			topM: "M 8 4 L 16 4 L 18 6 L 16 8 L 8 8 L 6 6 Z",
			midd: "M 8 18 L 16 18 L 18 20 L 16 22 L 8 22 L 6 20 Z",
			topL: "M 6 7 L 8 9 L 8 17 L 6 19 L 4 17 L 4 9 Z",
			topR: "M 18 7 L 20 9 L 20 17 L 18 19 L 16 17 L 16 9 Z",
			btmM: "M 8 32 L 16 32 L 18 34 L 16 36 L 8 36 L 6 34 Z",
			btmL: "M 6 21 L 8 23 L 8 31 L 6 33 L 4 31 L 4 23 Z",
			btmR: "M 18 21 L 20 23 L 20 31 L 18 33 L 16 31 L 16 23 Z"
		},
		seconds: {
			topM: [1, 0, 1, 1, 0, 1, 1, 1, 1, 1],
			midd: [0, 0, 1, 1, 1, 1, 1, 0, 1, 1],
			topL: [1, 0, 0, 0, 1, 1, 1, 0, 1, 1],
			topR: [1, 1, 1, 1, 1, 0, 0, 1, 1, 1],
			btmM: [1, 0, 1, 1, 0, 1, 1, 0, 1, 1],
			btmL: [1, 0, 1, 0, 0, 0, 1, 0, 1, 0],
			btmR: [1, 1, 0, 1, 1, 1, 1, 1, 1, 1]
		},
		tenSeconds: {
			topM: [1, 0, 1, 1, 0, 1],
			midd: [0, 0, 1, 1, 1, 1],
			topL: [1, 0, 0, 0, 1, 1],
			topR: [1, 1, 1, 1, 1, 0],
			btmM: [1, 0, 1, 1, 0, 1],
			btmL: [1, 0, 1, 0, 0, 0],
			btmR: [1, 1, 0, 1, 1, 1]
		},
		minutes: {
			topM: [1, 0, 1, 1, 0, 1, 1, 1, 1, 1],
			midd: [0, 0, 1, 1, 1, 1, 1, 0, 1, 1],
			topL: [1, 0, 0, 0, 1, 1, 1, 0, 1, 1],
			topR: [1, 1, 1, 1, 1, 0, 0, 1, 1, 1],
			btmM: [1, 0, 1, 1, 0, 1, 1, 0, 1, 1],
			btmL: [1, 0, 1, 0, 0, 0, 1, 0, 1, 0],
			btmR: [1, 1, 0, 1, 1, 1, 1, 1, 1, 1]
		},
		tenMinutes: {
			topM: [1, 0, 1, 1, 0, 1],
			midd: [0, 0, 1, 1, 1, 1],
			topL: [1, 0, 0, 0, 1, 1],
			topR: [1, 1, 1, 1, 1, 0],
			btmM: [1, 0, 1, 1, 0, 1],
			btmL: [1, 0, 1, 0, 0, 0],
			btmR: [1, 1, 0, 1, 1, 1]
		},
		hours: {
			topM: [1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0],
			midd: [1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0],
			topL: [0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0],
			topR: [1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1],
			btmM: [1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0],
			btmL: [1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0],
			btmR: [0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
		},
		tenHours: {
			topM: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
			midd: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
			topL: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
			topR: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
			btmM: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
			btmL: [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
			btmR: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
		}
	};

.........完整代码请登录后点击上方下载按钮下载查看

网友评论0