JSFiddle - React, Tailwind, and code Playground

by Yura Kosyak

HTML

<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.ui.rotatable/1.0.1/jquery.ui.rotatable.min.js"></script>
<div id="container">
  <div id="containment">
    <div id="circle" class="circle"></div>
  </div>
  <div id="containment2">
    <div id="circle2" class="circle">
      
    </div>
  </div>
</div>

CSS

#container {
  width: 100px;
  height: 140px;
  background: #FFEB3B;
  position: absolute;
  top: 50%;
  bottom: 50%;
  margin-top: -70px;
  margin-right: -50px;
}

.ui-rotatable-handle {
  height: 30px;
  width: 30px;
  cursor: pointer;
  background: #ff0000;
  border-radius: 50%;
  right: -15px;
  bottom: -15px;
  position: absolute;
  z-index: 1;
}

#containment,
#containment2 {
  width: 30px;
  height: 190px;
  position: absolute;
  bottom: 70px;
  left: 35px;
  border: solid 1px #000
}

#containment2 {
  width: 190px;
  height: 30px;
  left: 51px;
  bottom: 54px;
  transform: rotate(-90deg);
  border: solid 1px green;
  transform-origin: left;
  display: none;
}

.circle {
  width: 30px;
  height: 30px;
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  background: #3F51B5;
  z-index: 10;
}

#circle2 {
  left: calc(100% - 30px);
  display: none;
}

#wrapper {
  width: 100%;
  height: 100%;
  outline: 1px solid red;
}

JavaScript

$(function() {
  var Pi = 3.14;
  $('#container').draggable({}).rotatable({
    rotate: function(event, ui) {
      let deg = ui.angle.current * 180 / Pi;
      $("#containment").show();
      $("#containment2").hide();
      $("#circle").show();
      $("#circle2").hide();
      if (deg > 45) {
        $("#containment").hide();
        $("#containment2").show();
        $("#circle").hide();
        $("#circle2").show();
      }
    },
  });

  $('#circle').draggable({
    stop: function(event, ui) {
    	console.log(ui.position.top);
    	$("#circle2").css("inset", ui.position.left + "px auto auto " + (160 - ui.position.top) + "px");
    },
    containment: $('#containment')
  });
  $('#circle2').draggable({
    stop: function(event, ui) {
    	$("#circle").css("inset", 160 - ui.position.left + "px auto auto " + ui.position.top + "px");
    },
    containment: $('#containment2')
  });
  
});