JSFiddle - React, Tailwind, and code Playground

by joshmoto

HTML

<div id="zone">
  <div id="a"></div>
</div>

SCSS

#zone {
  background: black;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  cursor: crosshair;
}

#a {
  width: 2px;
  height: 50%;
  background: magenta;
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center;
  transition: all .05s ease;
  transform: translate(-1px,-50%);
  z-index: 1;
  
  &::before {
    content: '';
    display: block;
    position: absolute;
    width: 50px;
    height: 50px;
    top: -25px;
    left: 50%;
    background: magenta;
    transform: translate(-50%,0);
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  }
  
  &::after {
    content: '';
    display: block;
    position: absolute;
    background: white;
    z-index: -100;
    width: 2px;
    height: 500%;
    top: 0;
    left: 50%;
    transform: translate(-50%,-100%);
    opacity: 0.25;
  }  
}

JavaScript

// on ready
$(function() {

  const $zone = $('#zone');

  function calcAngleDegrees(x, y) {
    return Math.atan2(y, x) * 180 / Math.PI;
  }

  let currentMousePos = {
    x: -1,
    y: -1
  };
  
  let currentWin = {
    x: $zone.width(),
    y: $zone.height()
  };
  
  let currentWinSplit = {
    x: currentWin.x / 2,
    y: currentWin.y / 2
  };
  
  $zone.on('resize', function(e) {
  
  	currentWin = {
      x: $zone.width(),
      y: $zone.height()
    };
    
    currentWinSplit = {
      x: currentWin.x / 2,
      y: currentWin.y / 2
    };
  
  }).on('mousemove', function(e) {
    
    let quarterWin = {
    	x: -1,
      y: -1
    }

    // get our current mouse position
    currentMousePos.x = e.pageX - $zone.scrollLeft();
    currentMousePos.y = e.pageY - $zone.scrollTop();
    
    if(currentMousePos.x > currentWinSplit.x) {
    
    	quarterWin.x = currentMousePos.x - currentWinSplit.x;
    
    } else {
    
    	quarterWin.x = currentWinSplit.x - currentMousePos.x;

    }
    
    if(currentMousePos.y > currentWinSplit.y) {
    
    	quarterWin.y = currentMousePos.y - currentWinSplit.y;
    
    } else {
    
    	quarterWin.y = currentWinSplit.y - currentMousePos.y;
         
    }
    
    let corner_angle = calcAngleDegrees(quarterWin.x,quarterWin.y);
    let circle_angle = 0;
    
    if(currentMousePos.x > currentWinSplit.x) {
    
    		if(currentMousePos.y > currentWinSplit.y) {
        
          //console.log('bottom right');
        
        	circle_angle = 90 + corner_angle;
          
        } else {
        	
          //console.log('top right');
          
          circle_angle = 90 - corner_angle;
          
      	}
        
    } else {
    	
      if(currentMousePos.y > currentWinSplit.y) {
      
          //console.log('bottom left');
        
        	circle_angle = 270 - corner_angle;
          
          //console.log(circle_angle);
     
        
        } else {
        
          //console.log('top left');
        
     ...