js+css实现带刻度圆盘钟摆动画效果代码

代码语言:html

所属分类:动画

代码描述:js+css实现带刻度圆盘钟摆动画效果代码

代码标签: js css 刻度 圆盘 钟摆 动画

下面为部分代码预览,完整代码请点击下载或在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">
  
  <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;500&amp;display=swap'>
  
<style>
* {
	border: 0;
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
:root {
	--hue: 223;
	--hue2: 43;
	--bg: hsl(var(--hue),90%,90%);
	--fg: hsl(var(--hue),90%,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 "Barlow Condensed", sans-serif;
	height: 100vh;
	transition:
		background-color var(--trans-dur),
		color var(--trans-dur);
}
.clock {
	--angle: 0deg;
	background-color: hsl(var(--hue),10%,90%);
	background-image: radial-gradient(20% 20% at center,hsl(var(--hue),90%,70%) 49%,hsla(var(--hue),90%,70%,0) 50%);
	border-radius: 50%;
	box-shadow:
		0 0 0.0625em hsl(var(--hue),10%,70%),
		0.25em 0.25em 0.125em hsla(var(--hue),10%,10%,0.5);
	margin: auto;
	position: relative;
	width: 12em;
	height: 12em;
}
.clock:after,
.clock__hour,
.clock__pendulum,
.clock__pendulum:after,
.clock__pendulum-ball,
.clock__pendulum-ball:before,
.clock__pendulum-ball:after,
.clock__star,
.clock__star:after,
.clock__star-point {
	position: absolute;
}
.clock:after {
	background-image: linear-gradient(hsla(var(--hue),10%,10%,0),hsla(var(--hue),10%,10%,0.15));
	border-radius: inherit;
	content: "";
	width: 100%;
	height: 100%;
}
.clock__hour {
	background:
		linear-gradient(
			90deg,
			hsla(var(--hue),10%,10%,0) 0.7rem,
			hsl(var(--hue),10%,10%) 0.72rem 0.78rem,
			hsla(var(--hue),10%,10%,0) 0.8rem
		) 0 1.5rem / 100% 3rem no-repeat,
		linear-gradient(
			90deg,
			hsla(var(--hue),10%,10%,0) 0.7rem,
			hsl(var(--hue),10%,10%) 0.72rem 0.78rem,
			hsla(var(--hue),10%,10%,0) 0.8rem
		) 0 100% / 100% 0.75rem no-repeat;
	color: hsl(var(--hue),10%,10%);
	display: flex;
	font-size: 0.75em;
	font-weight: 500;
	line-height: 2;
	justify-content: center;
	align-items: flex-end;
	padding-bottom: 0.5em;
	top: 50%;
	left: calc(50% - 0.75rem);
	width: 1.5rem;
	height: 50%;
	transform: rotate(0);
	transform-origin: 50% 0;
}
.clock__hour:nth-child(2) { transform: rotate(15deg); }
.clock__hour:nth-child(3) { transform: rotate(30deg); }
.clock__hour:nth-child(4) { transform: rotate(45deg); }
.clock__hour:nth-child(5) { transform: rotate(60deg); }
.clock__hour:nth-child(6) { transform: rotate(75deg); }
.clock__hour:nth-child(7) { transform: rotate(90deg); }
.clock__hour:nth-child(8) { transform: rotate(105deg); }
.clock__hour:nth-child(9) { transform: rotate(120deg); }
.clock__hour:nth-child(10) { transform: rotate(135deg); }
.clock__hour:nth-child(11) { transform: rotate(150deg); }
.clock__hour:nth-child(12) { transform: rotate(165deg); }
.clock__hour:nth-child(13) { transform: rotate(180deg); }
.clock__hour:nth-child(14) { transform: rotate(195deg); }
.clock__hour:nth-child(15) { transform: rotate(210deg); }
.clock__hour:nth-child(16) { transform: rotate(225deg); }
.clock__hour:nth-child(17) { transform: rotate(240deg); }
.clock__hour:nth-child(18) { transform: rotate(255deg); }
.clock__hour:nth-child(19) { transform: rotate(270deg); }
.clock__hour:nth-child(20) { transform: rotate(285deg); }
.clock__hour:nth-child(21) { transform: rotate(300deg); }
.clock__hour:nth-child(22) { transform: rotate(315deg); }
.clock__hour:nth-child(23) { transform: rotate(330deg); }
.clock__hour:nth-child(24) { transform: rotate(345deg); }

.clock__pendulum {
	top: 0;
	left: calc(50% - 0.75em);
	width: 1.5em;
	height: 12em;
	transform: rotate(var(--angle));
	z-index: 1;
}
.clock__pendulum:after,
.clock__pendulum-ball {
	animation: pendulumBall 2s -0.5s ease-in-out infinite;
}
.clock__pendulum:after {
	animation-name: pendulumChord;
	background-color: hsl(var(--hue2),70%,30%);
	border-radius: 0.0625em;
	content: "";
	display: block;
	top: 50%;
	left: calc(50% - 0.0625em);
	width: 0.125em;
	height: 50%;
	transform: rotateX(-90deg);
	transform-origin: 50% 0;
}
.clock__pendulum-ball {
	background-color: hsl(var(--hue2),70%,50%);
	border-radius: 50%;
	top: calc(50% - 0.75em);
	left: calc(50% - 0.75em);
	width: 1.5em;
	height: 1.5em;
}
.clock__pendulum-ball:before,
.clock__pendulum-ball:after {
	border-radius: inherit;
	content: "";
	display: block;
}
.clock__pendulum-ball:before {
	background-image:
		radial-gradient(25% 25% at 70% 30%,hsl(var(--hue2),70%,90%) 25%,hsla(var(--hue2),70%,90%,0) 50%);
	box-shadow:
		0 0 0.5em hsla(var(--hue),10%,10%,0.5) inset,
		0.25em 0.25em 0.0625em hsla(var(--hue),10%,10%,0.5);
	width: 100%;
	height: 100%;
	transform: rotate(calc(var(--angle) * -1));
}
.clock__pendulum-ball:after {
	background-color: hsl(var(--hue2),70%,45%);
	box-shadow: 0 0 0.125em hsla(var(--hue2),10%,.........完整代码请登录后点击上方下载按钮下载查看

网友评论0