效果
代码
<!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>
@keyframes rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
div {
position: relative;
width: 100px;
height: 100px;
background: radial-gradient(white, #0089FF);
border-radius: 50%;
}
.point {
position: absolute;
top: -10px;
left: 50%;
width: 8px;
height: 8px;
background-color: blue;
border-radius: 50%;
}
.container {
position: relative;
width: 100px;
height: 100px;
animation: rotate 2s linear infinite;
margin: 50px auto;
}
</style>
</head>
<body>
<div class="container">
<div class="circle"></div>
<div class="point"></div>
</div>
</body>
</html>
实现步骤
- 使用@keyframes定义一个旋转动画,设置初始角度为0度,每隔一段时间增加一定的角度值,直到达到360度为止。
- 在圆的div元素上添加一个点,并设置其样式为圆形,大小和颜色与圆相同。
- 将圆的div元素和点所在的div元素都放置在一个容器中,并设置容器的旋转动画为刚才定义的rotate动画。