2013-03-03 54 views
0

我是KineticJS的新手,無法在mousedown上獲得舞臺的鼠標座標。我設法用mouseoutmouseover顯示座標,但mousedown似乎只適用於已添加到舞臺的圖像/形狀,但不是舞臺本身。如何獲取我點擊的位置的鼠標位置,在kinetic.js階段?

任何人都可以向我解釋爲什麼這樣嗎?請幫我解決問題。

this is the example我試着用:


代碼:

stage.on('mouseout', function() { 
     var mousePos = stage.getMousePosition(); 
     writeMessage(messageLayer, 'Mouseout triangle:' + mousePos.x); 
    }); 

    stage.on('mouseout','mousemove', function() { 

    }); 

    stage.on('mousedown', function() { 
     alert('OK!'); 
    }); 

回答

1

jQuery的事件偵聽器的功能有,你永遠需要包含的所有信息傳遞事件PARAMS。在這種情況下,您可能需要offsetX和offsetY。

$('body').click(function (e) { 
    console.log(e.offsetX, e.offsetY); 
}); 
+0

感謝兄弟,設法通過JQuery來完成它:) – Milind 2013-03-04 19:07:31