JSFiddle - React, Tailwind, and code Playground

by Laxmikant Dange

HTML

<script src="https://jqueryrotate.googlecode.com/files/jQueryRotate.js"></script>
<div id='striker'></div>

CSS

#striker {
    position:absolute;
    width:10px;
    height:50px;
    background:#F00;
    left:400px;
    top:400px;
}

JavaScript

$(document).on('mousemove', rotateStriker);

function rotateStriker(e) {
    var mouseX=e.clientX;
    var mouseY=e.clientY;
    
    var angle=getAngle({x:400,y:400},{x:mouseX,y:mouseY});
    $("#striker").rotate(angle-90)
}

function getAngle(p1, p2) {
    var angleRadians = Math.atan2(p2.y - p1.y, p2.x - p1.x);
    return angleRadians*180/Math.PI; 
}