一、实现效果
二、代码示例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* 设置表的外壳 */
.clock{
width: 400px;
height: 400px;
/* background-color: cyan; */
margin: 100px auto;
position: relative;
border-radius: 50%;
background-image: url("./images/bg.png");
background-size: cover;
}
.clock > div{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
/* 设置秒针 */
.seconds-wrapper{
width: 300px;
height: 300px;
/* background-color: rgb(55, 20, 255); */
animation: run 60s steps(60) infinite;
}
.seconds-wrapper .seconds{
height: 50%;
width: 2px;
margin: 0 auto;
background-color: red;
}
/* 设置分针 */
.minute-wrapper{
width: 300px;
height: 250px;
/* background-color: aliceblue; */
animation: run 3600s steps(60) infinite;
}
.minute-wrapper .minute{
width: 4px;
height: 50%;
margin: 0 auto;
background-color: black;
}
/* 设置时针 */
.hour-wrapper{
width: 200px;
height: 200px;
/* background-color: chartreuse; */
animation: run 216000s infinite;
}
.hour-wrapper .hour{
width: 6px;
height: 50%;
margin: 0 auto;
background-color: black;
}
@keyframes run {
from{
transform: rotateZ(0);
}
to{
transform: rotateZ(360deg);
}
}
</style>
</head>
<body>
<div class="clock">
<div class="seconds-wrapper">
<div class="seconds"></div>
</div>
<div class="minute-wrapper">
<div class="minute"></div>
</div>
<div class="hour-wrapper">
<div class="hour"></div>
</div>
</div>
</body>
</html>