Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    html, body {
        height: 100%;
        position: relative;
    }
    
    .triangle {
        width: 100px;
        height: 100px;
        background: red;
        border-radius: 50%;
        position: absolute;
        margin: 20% 50%;
        text-align: center;
        line-height: 100px;
        font-weight: bold;
    }
  </style>
</head>
<body>
  <div class="triangle">>>>>>>>></div>
  <script>
    var followMouseCursor = function (event) {
        event = event || window.event;
        
        var triangle = document.querySelector('.triangle');
        var xDist = event.layerX - triangle.offsetLeft;
        var yDist = event.layerY - triangle.offsetTop;
        var angle = Math.atan2(yDist, xDist) * (180 / Math.PI);
        
        triangle.style.transform = 'rotate(' + angle + 'deg)';
    };
    
    document.body.addEventListener('mousemove', followMouseCursor);
  </script>
</body>
</html>
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers