Skip to content

Instantly share code, notes, and snippets.

@mdecourse
Last active September 4, 2019 13:24
Show Gist options
  • Select an option

  • Save mdecourse/5223cb3dca5cd45f5b7ea7bd791a4034 to your computer and use it in GitHub Desktop.

Select an option

Save mdecourse/5223cb3dca5cd45f5b7ea7bd791a4034 to your computer and use it in GitHub Desktop.
Get mouse coordinate in Dartpad
<canvas id="canvas" width="300" height="300"></canvas>
<div id="output"></div>
import 'dart:html';
CanvasElement canvas = querySelector('#canvas');
CanvasRenderingContext2D context = canvas.getContext('2d');
DivElement output = querySelector("#output");
void main(){
document.body.style.backgroundColor = "black";
canvas.onMouseMove.listen((e) {
output.text = "x:" + (e.client.x).toString() + ", y:" +(e.client.y).toString();
});
}
html, body{
color: white;
font-size: 25px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment