A Pen by Captain Anonymous on CodePen.
Created
March 1, 2016 11:17
-
-
Save arvind-iyer/05cd2e0b5735288057a8 to your computer and use it in GitHub Desktop.
jqEzZy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<canvas id="canvas" width="640" height="360"></canvas> | |
<div class="test"> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", init, false); | |
function init() | |
{ | |
var canvas = document.getElementById("canvas"); | |
canvas.addEventListener("mousedown", getPosition, false); | |
} | |
function getPosition(event) | |
{ | |
var x = new Number(); | |
var y = new Number(); | |
var canvas = document.getElementById("canvas"); | |
if (event.x != undefined && event.y != undefined) | |
{ | |
x = event.x; | |
y = event.y; | |
} | |
else // Firefox method to get the position | |
{ | |
x = event.clientX + document.body.scrollLeft + | |
document.documentElement.scrollLeft; | |
y = event.clientY + document.body.scrollTop + | |
document.documentElement.scrollTop; | |
} | |
x -= canvas.offsetLeft; | |
y -= canvas.offsetTop; | |
var test = $('.test'); | |
test.text("x: " + x + " y: " + y); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#canvas { | |
background-color: #000; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment