JSFiddle - React, Tailwind, and code Playground

by enagu

HTML

<div id="resizable" class="mini-flex-rep">
  <button class="close-mf-button">x</button>
  <button id="move-mfr-btn" class="move-mf-button">☩</button>
  
  <iframe src="https://www.youtube.com/embed/Xmw9SWJ0L50" frameborder="0"></iframe>
</div>

SCSS

html, body{
  width: 100%;
  height: 100%;
  
  background-color: #222;
}

.mini-flex-rep{
  z-index: 9999999; 
  position: absolute; 
  top: 0;
  left: 0;
  width: 90%; 
  height: 90%; 
  resize: both; 
  overflow: auto;
  background-color: #fff;
  
  iframe {
    width: 100%;
    height: 100%;
  }
}
  
button.close-mf-button{
    display: block;
    position: absolute;
    right: 0;
    top: 10px;
    width: 25px;
    height: 22px;
    text-align: center;
}
  
button.move-mf-button{
  display: block;
  position: absolute;
  right: 22px;
  top: 10px;
  width: 25px;
  height: 22px;
  text-align: center;
}

JavaScript

let r = document.getElementById('move-mfr-btn');
dragElement(r);

function dragElement(elmnt) {
  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
 	elmnt.onmousedown = dragMouseDown;
  var eltomove = elmnt.parentElement;

  function dragMouseDown(e) {
    e = e || window.event;
    e.preventDefault();
    // get the mouse cursor position at startup:
    pos3 = e.clientX;
    pos4 = e.clientY;
    document.onmouseup = closeDragElement;
    // call a function whenever the cursor moves:
    document.onmousemove = elementDrag;
  }

  function elementDrag(e) {
    e = e || window.event;
    e.preventDefault();
    // calculate the new cursor position:
    pos1 = pos3 - e.clientX;
    pos2 = pos4 - e.clientY;
    pos3 = e.clientX;
    pos4 = e.clientY;
    // set the element's new position:
    eltomove.style.top = (eltomove.offsetTop - pos2) + "px";
    eltomove.style.left = (eltomove.offsetLeft - pos1) + "px";
  }

  function closeDragElement() {
    // stop moving when mouse button is released:
    document.onmouseup = null;
    document.onmousemove = null;
  }
}