<!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>
.f {
position: realtive;
left: 0;
top: 0;
width: 300px;
height: 300px;
border: 1px solid #ccc;
}
.f .c {
position: absolute;
/* top: 40px;
left: 10px; */
width: 2px;
height: 20px;
/* border-radius: 50%; */
background-color: red;
transform-origin: top center;
}
</style>
</head>
<body>
<div class="f">
<!-- <div class="c"></div> -->
</div>
<script>
const c = document.querySelector('.c')
const f = document.querySelector('.f')
const total = 50
const startAng = Math.PI / total
const r = 75
console.log(startAng)
for (let i = 0; i <= total; i++) {
const dom = document.createElement('div')
dom.className = 'c'
const x = r * Math.cos(Math.PI + i * startAng)
const y = r * Math.sin(Math.PI + i * startAng)
dom.style.top = `${y + 305}px`
dom.style.left = `${x + 150}px`
console.log((180 / Math.PI) * (i * startAng))
const a = (180 / Math.PI) * (i * startAng)
const ang = - (90 - a);
// dom.style.transform-origin
dom.style.transform = 'rotate(' + ang + 'deg)'
f.appendChild(dom)
}
</script>
</body>
</html>
效果: