mouse-distance.js 386 B

1234567891011121314151617
  1. var stage = new mtm.Stage('c'),
  2. shape = new Rect(stage.width/2, stage.height/2);
  3. stage.shapes.push(shape);
  4. stage.canvas.addEventListener("mousemove", function(e) {
  5. var mx = e.offsetX || e.clientX,
  6. my = e.offsetY || e.clientY,
  7. dx = shape.x - mx,
  8. dy = shape.y - my,
  9. dist = Math.sqrt(dx*dx + dy*dy);
  10. stage.cleanRender();
  11. console.log(dist);
  12. }, false);