我正在尝试旋转父圆并消除对其子圆的影响。我尝试使用以下方法消除影响
transform: translate(-50%, -50%)
rotate(calc(var(--i) * -60deg))
translateY(150px)
rotate(calc(var(--i) * 60deg - var(--rotation)))
但是子元素在过渡开始时会旋转 60 度。如何防止它们在过渡期间完全旋转?
const circle = document.getElementById('circle');
let deg = 0;
function rotate() {
deg += 60;
circle.style.cssText = `--rotation: ${deg}deg`;
}
.circle {
border: 2px solid #ccc;
border-radius: 50%;
height: 300px;
margin: 40px auto 0;
transform: rotate(var(--rotation));
transition: transform 1000ms ease;
position: relative;
width: 300px;
}
.item {
align-items: center;
background: red;
border: 2px solid #fff;
border-radius: 50%;
display: flex;
height: 30px;
justify-content: center;
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%) rotate(calc(var(--i) * -60deg)) translateY(150px) rotate(calc(var(--i) * 60deg - var(--rotation)));
width: 30px;
}
.btn {
align-items: center;
background: lawngreen;
display: flex;
height: 30px;
justify-content: center;
width: 100px;
}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="circle" id="circle" style="--rotation: 0deg">
<div class="item" style="--i: 0">1</div>
<div class="item" style="--i: 1">2</div>
<div class="item" style="--i: 2">3</div>
<div class="item" style="--i: 3">4</div>
<div class="item" style="--i: 4">5</div>
<div class="item" style="--i: 5">6</div>
</div>
<div class='btn' onclick="rotate()">rotate</div>
你已经快完成了,只需向子元素添加相同的过渡即可