2010-02-25 69 views
0

編輯:解決如何獲得當前光標座標的JavaScript

好吧,我的問題是,我需要找到一種方式來不斷地讀取X,光標的y座標在瀏覽器中onmousedown事件,然後到退出閱讀x,y座標onmouseup這裏是我到目前爲止


var mouseDown = 0; 
var xPos = 0; 
var yPos = 0; 

document.body.onmousedown = function() { 
    mouseDown = 1; 
} 
document.body.onmouseup = function() { 
    mouseDown = 0; 
} 
function resize(width, height){ 
    document.getElementById('component1').width=width; 
    document.getElementBYId('component1').height=height; 
} 
function setSize(){ 
    while(mouseDown == 1) 
    { 
     xPos = event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); 
     yPos = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? 
document.documentElement.scrollTop : document.body.scrollTop); 
     resize(xPos, yPos); 
    } 

} 

有什麼建議嗎?

回答

1
+0

我不能當鼠標按下事件發生時,這個工作。你會怎麼做? – AFK 2010-02-25 09:07:58

+0

讓它工作。 – AFK 2010-02-25 11:16:05

+0

@Matt這是相同的頁面http://www.javascriptsource.com/page-details/mouse-coordinates.html您的鏈接現在已經死了? – 2012-06-14 06:16:28

相關問題