简介:
该案例中旋转的并非是指针,而是将背景设置为透明色的指针父元素。
对于实现钟表效果,只需要将指针父元素块在clock中居中,然后指针在其父元素中居中,让指针父元素旋转即可。
效果图:
背景:
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>时钟</title>
<link rel="stylesheet" href="../02CSS/reset.css">
<style>
.clock,.clock > div{
position: absolute;
left: 0px;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
.clock{
width: 700px;
height: 700px;
background-image: url("img/13/bg.png");
background-size: cover;
overflow: hidden;
}
.clock .sec-wrapper{
width: 600px;
height: 600px;
animation: run 60s infinite steps(60);
}
.clock .sec-wrapper .sec{
width: 10px;
height: 280px;
margin: 0px auto;
margin-top: 20px;
background-color: black;
}
.clock .mine-wrapper{
width: 500px;
height: 500px;
animation: run 3600s steps(60) infinite;
}
.clock .mine-wrapper .mine{
width: 10px;
height: 230px;
margin: 0px auto;
margin-top: 20px;
background-color: rgb(90, 90, 90);
}
.clock .hour-wrapper{
width: 400px;
height: 400px;
animation: run 216000s steps(60) infinite;
}
.clock .hour-wrapper .hour{
width: 10px;
height: 180px;
margin: 0px auto;
margin-top: 20px;
background-color: rgb(197, 197, 197);
}
.clock .turn{
width: 20px;
height: 20px;
margin-top: 338px;
margin-left: 338px;
background-color: black;
border-radius: 50%;
box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.9);
}
@keyframes run{
from{
transform: rotateZ(0deg);
}
to{
transform: rotateZ(360deg);
}
}
</style>
</head>
<body>
<div class="clock">
<div class="hour-wrapper">
<div class="hour"></div>
</div>
<div class="mine-wrapper">
<div class="mine"></div>
</div>
<div class="sec-wrapper">
<div class="sec"></div>
</div>
<div class="turn"></div>
</div>
</body>
</html>
积跬步,至千里!加油,学习人!