瀏覽代碼

Clamp mouseclick coordinates to target element bounds

jalf 12 年之前
父節點
當前提交
8a147535de
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      include/util.js

+ 3 - 1
include/util.js

@@ -298,7 +298,9 @@ Util.getEventPosition = function (e, obj, scale) {
     if (typeof scale === "undefined") {
         scale = 1;
     }
-    return {'x': (docX - pos.x) / scale, 'y': (docY - pos.y) / scale};
+    var x = Math.max(Math.min(docX - pos.x, obj.width-1), 0);
+	var y = Math.max(Math.min(docY - pos.y, obj.height-1), 0);
+    return {'x': x / scale, 'y': y / scale};
 };