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>
</head>
<body>
    <p class="tc">
        <canvas id="mundo"></canvas>
    </p>
    <h3 id="msj"></h3>
</body>
</html>
 
var canvas = document.getElementById('mundo');
function getMousePos(canvas, evt){
    var rect = canvas.getBoundingClientRect();
    return{
        x: evt.clientX - rect.left,
        y: evt.clientY - rect.top
    };
}
canvas.addEventListener('mousemove', function(evt){
    var mousePos = getMousePos(canvas, evt);
    msj = ('Mouse position: ' + mousePos.x + ', ' + mousePos.y);
    document.getElementById('msj').innerHTML = msj;
}, false);
Output

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