<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
font-family: "Microsoft YaHei", serif;
}
body, dl, dd, p, h1, h2, h3, h4, h5, h6 {
margin: 0;
}
ol, ul, li {
margin: 0;
padding: 0;
list-style: none;
}
img {
border: none
}
#wrap{
position: relative;
width: 500px;
height: 500px;
margin: 50px auto;
border: 1px solid #999;
border-radius: 50%;
}
#wrap p.ball{
position: absolute;
top: 0;
left: 250px;
width: 30px;
height: 30px;
margin-left: -15px;
margin-top: -15px;
background-color: pink;
border-radius: 50%;
}
</style>
</head>
<body>
<div id="wrap">
<p class="ball"></p>
</div>
<script>
// 一般能用css3做的动画 都不用js做
// requestAnimationFrame比setInterval更流畅
let oBall = document.querySelector("#wrap p.ball");
let oWrap = document.getElementById("wrap");
let d = 0;
let timer;
requestAnimationFrame(
function move() {
d += 0.01;
let left = Math.sin(d) * 250 + 250;
let top = 250 - Math.cos(d) * 250;
oBall.style.left = left + "px";
oBall.style.top = top + "px";
timer = requestAnimationFrame(move);
}
);
oWrap.onclick = function () {
cancelAnimationFrame(timer)
};
</script>
</body>
</html>
Python3Turtle