JSFiddle - React, Tailwind, and code Playground

by Natcher86

HTML

<div id="scene">
    <div class="object">
    </div>
</div>

CSS

#scene {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 200px;
    height: 200px;
    margin: -100px 0 0 -100px;
    background-color: red;
}

.object {
    position: absolute;
    left: 50px;
    top: 50px;
    width: 50px;
    height: 50px;
    background-color: blue;
}

JavaScript

var object = document.getElementsByClassName('object'),
    scene = document.getElementById('scene'),
    width = $('scene').width(),
    height = $('scene').height();

function initMove() {

  for(var i=0; i<object.length; i++) {

      object[i].addEventListener("mousemove", function(event) {
        //event.stopPropagation();
        return false;
      }, false);
  }

  scene.addEventListener("mousemove", function (event) {
    //event.stopPropagation();
    //event.currentTarget;
    width = $('scene').width();
    height = $('scene').height();
    moveX = width+event.offsetX;
    moveY = height+event.offsetY;
    console.log(moveX + ' + ' + moveY);
  }, false);

}

function init() {
  initMove();
  document.onselectstart = function(){ return false; }
};

init();