JSFiddle - React, Tailwind, and code Playground

by tgienger

HTML

<div id="parent">
    <div id="child">
        <div id="indicator"></div>
    </div>
</div>

CSS

#parent {
    position: relative;
    width: 200px;
    height: 200px;
    border: 1px solid black;
    border-radius: 100%;
}

#child {
    position: absolute;
    top: 2px;
    left: 75px;
    width: 50px;
    height: 50px;
    border: 1px solid red;
    border-radius: 100%;
}

#indicator {
    position: absolute;
    top: 0;
    left: 24px;
    background: black;
    width: 2px;
    height: 20px;
}

JavaScript

function getEl(name) {
	return document.querySelector(name);
}

var parent = getEl('#parent');
var child = getEl('#child');
var deg = 0;

function rotate(deg) {
	parent.style.transform = 'rotate('+deg+'deg)';
    child.style.transform = 'rotate(-'+deg+'deg)';
}

function spin() {
    deg = deg < 360 ? deg + 1 : 0;
    rotate(deg);
}

var spinning = window.setInterval(spin, 10);