js+css实现齿轮时钟显示时间代码

代码语言:html

所属分类:其他

代码描述:js+css实现齿轮时钟显示时间代码

代码标签: js css 齿轮 时钟 显示 时间 代码

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

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

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

  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Squada+One&display=swap");

:root {
	--main_bg: #111111;
	--gear_bg: #686d76;
	--gearbox_size: 12rem;
	--gearwheel_size: 30rem;
}

* {
	padding: 0;
	margin: 0;
	box-sizing: border-box;
}

body {
	height: 100vh;
	width: 100%;
	background: var(--main_bg);
}

.main {
	height: 100%;
	width: 100%;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	gap: 4rem;
}

p {
	font-size: 6rem;
	color: white;
	font-family: "Squada One";
}

.clock {
	display: flex;
	align-items: center;
	justify-content: center;
}

.gearbox {
	height: var(--gearbox_size);
	width: var(--gearbox_size);
	position: relative;
	overflow: hidden;
}

.gearcover {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	z-index: 10;
	background: linear-gradient(
		var(--main_bg),
		transparent 33.33%,
		transparent 66.66%,
		var(--main_bg)
	);
}

.hours,
.minutes,
.seconds {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: 1rem;
}

.gear3,
.gear6,
.gear9 {
	position: absolute;
	height: var(--gearwheel_size);
	width: var(--gearwheel_size);
	border-radius: 50%;
	background: radial-gradient(
		transparent 50%,
		var(--gear_bg) 50%,
		var(--gear_bg)
	);
	margin-top: calc((-1) * (var(--gearwheel_size) / 2 - var(--gearbox_size) / 2));
	transition: transform 0.3s linear;
	box-shadow: 0 0 15px black;
}

.gear3 div,
.gear6 div,
.gear9 div {
	position: absolute;
	height: 4rem;
	width: calc(var(--gearwheel_size) / 2);
	margin-top: calc(var(--gearwheel_size) / 2 - 2rem);
}

.gear3,
.gear6 {
	margin-left: calc(var(--gearbox_size) - var(--gearwheel_size));
}

.gear3 div {
	text-align: end;
	margin-left: calc(var(--gearwheel_size) / 2);
	transform: rotate(calc(var(--n) * 120deg));
	transform-origin: left center;
}

.gear6 div {
	text-align: end;
	margin-left: calc(var(--gearwheel_size) / 2);
	transform: rotate(calc(var(--n) * 60deg));
	transform-origin: left center;
}

.gear9 div {
	margin-left: 0;
	transform: rotate(calc(var(--n) * -36deg));
	transform-origin: right center;
}

.gear3 div span,
.gear6 div span,
.gear9 div span {
	line-height: 4rem;
	font-size: 3.5rem;
	margin: 0 1.5rem;
	color: white;
	font-family: "Outfit";
	text-shadow: 0 0 5px black;
}
</style>


  
  
</head>

<body translate="no">
  <div class="main">
	<p>Gear Clock</p>

	<div class="clock">
		<div class="hours">
			<div class="gearbox">
				<div class="gearcover"></div>
				<div class="gear3" id="gh3">
					<div style="--n: 0"><span>0</span></div>
					<div style="--n: 1"><span>1</span></div>
					<div style="--n: 2"><span>2</span></div>
				</div>
			</div>

			<div class="gearbox">
				<div class="gearcover"></div>
				<div class="gear9" id="gh9">
					<div style="--n: 0"><span>0</span></div>
					<div style="--n: 1"><span>1</span></div>
					<div style="--n: 2"><span>2</span></div>
					<div style="--n: 3"><span>3</span></div>
					<div style="--n: 4"><span>4</span></div>
					<div style="--n: 5"><span>5</span></div>
					<div style="--n: 6"><span>6</span></div>
					<div style="--n: 7"><span>7</span></div>
					<div style="--n: 8"><span>8</span></div>
					<div style="--n: 9"><span>9</span></div>
				</div>
			</div>
		</div>

		<div class="minutes">
			<div class="gearbox">
				<div class="gearcover"></div>
				<div class="gear6" id="gm6">
					<div style="--n: 0"><span>0</span></div>
					<div style="--n: 1"><span>1</span></div>
					<div style="--n: 2"><span>2</span></div>
					<div style="--n: 3"><span>3</span></div>
					<div style="--n: 4"><span>4</span></div>
					<div style="--n: 5"><span>5</span></div>
				</div>
			</div>

			<div class="gearbox">
				<div class="gearcover&.........完整代码请登录后点击上方下载按钮下载查看

网友评论0