<!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>
* {
padding: 0;
margin: 0;
}
.taiji {
width: 240px;
height: 120px;
border-width: 2px 2px 120px 2px;
border-style: solid;
border-color: black;
margin: 120px auto;
border-radius: 50%;
position: relative;
animation: rotate 5s linear infinite;
}
.taiji::after {
content: "";
position: absolute;
width: 28px;
height: 28px;
top: 50%;
background-color: black;
border-radius: 50%;
border: solid 46px white;
}
.taiji::before {
content: "";
position: absolute;
width: 28px;
height: 28px;
left: 50%;
top: 50%;
border-radius: 50%;
background-color: white;
border: solid 46px black;
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="taiji"></div>
<button id="rotate-btn">旋转</button>
</body>
<script>
const taiji = document.querySelector('.taiji');
const btn = document.querySelector('#rotate-btn');
let speed = 5;
function startRotation() {
taiji.style.animation = `rotate ${speed}s linear infinite`;
speed -= speed/3;
}
btn.addEventListener('click', startRotation);
</script>
</html>
效果就是一个会转的小太极