//get mouse position relative to the document
function mousePos (e) {
var x,y;
var e = e || window.event;
return {
x:e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
y:e.clientY + document.body.scrollTop + document.documentElement.scrollTop
}
}
//test function mousePos(e)
function test(event){
document.getElementById("mjs").innerHTML = mousePos(event).x + ',' + mousePos(event).y;
}
1 Response
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.