css+js实现数字中性时钟显示当前时分秒走动效果代码

代码语言:html

所属分类:布局界面

代码描述:css+js实现数字中性时钟显示当前时分秒走动效果代码

代码标签: css js 数字 中性 时钟 显示 当前 走动

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

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

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

  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  
  
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--hue: 223;
	--bg: hsl(var(--hue),10%,90%);
	--fg: hsl(var(--hue),10%,10%);
	--primary: hsl(var(--hue),90%,50%);
	--trans-dur: 0.3s;
	font-size: calc(16px + (32 - 16) * (100vw - 320px) / (2560 - 320));
}
body {
	background-color: var(--bg);
	color: var(--fg);
	display: flex;
	font: 1em/1.5 sans-serif;
	height: 100vh;
	transition:
		background-color var(--trans-dur),
		color var(--trans-dur);
}
.clock {
	--shadow1: hsl(var(--hue),10%,60%);
	--shadow2: hsl(0,0%,100%);
	display: flex;
	align-items: center;
	margin: auto;
}
.clock__colon {
	margin-left: 0.5em;
	position: relative;
	width: 0.75em;
	height: 2.25em;
}
.clock__colon:before,
.clock__colon:after,
.clock__digit-stroke {
	box-shadow:
		0.1em 0.1em 0.2em var(--shadow1),
		-0.1em -0.1em 0.2em var(--shadow2),
		-0.05em -0.05em 0.1em var(--shadow1) inset,
		0.05em 0.05em 0.1em var(--shadow2) inset;
	position: absolute;
	transition: box-shadow var(--trans-dur);
}
.clock__colon:before,
.clock__colon:after {
	border-radius: 50%;
	content: "";
	display: block;
	top: 0.125em;
	left: 0.125em;
	width: 0.5em;
	height: 0.5em;
}
.clock__colon:after {
	top: auto;
	bottom: 0.125em;
}
.clock__digit {
	position: relative;
	width: 2em;
	height: 3.5em;
}
.clock__digit ~ .clock__digit {
	margin-left: 0.5em;
}
.clock__digit-stroke {
	border-radius: 0.25em;
	top: 0;
	left: 0;
	width: 1em;
	height: 0.5em;
}
.clock__digit-stroke:nth-child(1),
.clock__digit-stroke:nth-child(4),
.clock__digit-stroke:nth-child(7) {
	left: 0.5em;
}
.clock__digit-stroke:nth-child(2),
.clock__digit-stroke:nth-child(3),
.clock__digit-stroke:nth-child(5),
.clock__digit-stroke:nth-child(6) {
	width: 0.5em;
	height: 1em;
}
.clock__digit-stroke:nth-child(2),
.clock__digit-stroke:nth-child(3) {
	top: 0.5em;
}
.clock__digit-stroke:nth-child(3),
.clock__digit-stroke:nth-child(6) {
	right: 0;
	left: auto;
}
.clock__digit-stroke:nth-child(5),
.clock__digit-stroke:nth-child(6) {
	top: auto;
	bottom: 0.5em;
}
.clock__digit-stroke:nth-child(4) {
	top: 1.5em;
}
.clock__digit-stroke:nth-child(7) {
	top: auto;
	bottom: 0;
}
.clock__digit--small {
	transform: scale(0.5);
	transform-origin: 0 100%;
}
.clock__digit--small ~ .clock__digit--small {
	margin-right: -2em;
	transform: scale(0.5) translateX(-125%);
}
[data-digit="0"] .clock__digit-stroke:nth-child(4),
[data-digit="1"] .clock__digit-stroke:nth-child(1),
[data-digit="1"] .clock__digit-stroke:nth-child(2),
[data-digit="1"] .clock__digit-stroke:nth-child(4),
[data-digit="1"] .clock__digit-stroke:nth-child(5),
[data-digit="1"] .clock__digit-stroke:nth-child(7),
[data-digit="2"] .clock__digit-stroke:nth-child(2),
[data-digit="2"] .clock__digit-stroke:nth-child(6),
[data-digit="3"] .clock__digit-stroke:nth-child(2),
[data-digit="3"] .clock__digit-stroke:nth-child(5),
[data-digit="4"] .clock__digit-stroke:nth-child(1),
[data-digit="4"] .clock__digit-stroke:nth-child(5),
[data-digit="4"] .clock__digit-stroke:nth-child(7),
[data-digit="5"] .clock__digit-stroke:nth-child(3),
[data-digit="5"] .clock__digit-stroke:nth-child(5),
[data-digit="6"] .clock__digit-stroke:nth-child(3),
[data-digit="7"] .clock__digit-stroke:nth-child(2),
[data-digit="7"] .clock__digit-stroke:nth-child(4),
[data-digit="7"] .clock__digit-stroke:nth-child(5),
[data-digit="7"] .clock__digit-stroke:nth-child(7),
[data-digit="9"] .clock__digit-stroke:nth-child(5) {
	box-shadow:
		0 0 0 var(--shadow1),
		0 0 0 var(--shadow2),
		0 0 0 var(--shadow1) inset,
		0 0 0 var(--shadow2) inset;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
	:root {
		--bg: hsl(var(--hue),10%,30%);
		--fg: hsl(var(--hue),10%,90%);
	}
	.clock {
		--shadow1: hsl(var(--hue),10%,10%);
		--shadow2:  hsl(var(--hue),10%,50%);
	}
}
</style>



  
  
</head>

<body>
  <div class="clock" role="img">
	<div class="clock__digit" data-digit="0">
		<div class="clock__digit-stroke"></.........完整代码请登录后点击上方下载按钮下载查看

网友评论0