Jump to content

Mouse coordinates script?


clonetrooper9494
 Share

Recommended Posts

I need a script that would get the coordinates of the mouse, or cursor and save them in a variable, so I can use them for another thing... and I have IE 7, and have heard it doesn't work well with some scripts... are there other ways that will work with IE 7? If so, is there a site that has a script? I have googled it, but I can not find one that works!

Link to comment
Share on other sites

This works for me in Firefox and IE6. I don't have IE7, so I can't test it for you:

<html><body><div id="out"></div><script type="text/javascript">function show_coords(e){	e = (e) ? e : window.event;	var x = e.clientX;	var y = e.clientY;	document.getElementById("out").innerHTML = "(" + x + "," + y + ")";}document.onmousemove = show_coords;</script></body></html>

Link to comment
Share on other sites

I am having a little bit of a problem... I want to change the TOP and LEFT elements of a div/span... how do I do that? I have tried:document.getElementById('out').top = x_coor;document.getElementById('out').style.top = x_coor;nothing works!!

Link to comment
Share on other sites

I am having a little bit of a problem... I want to change the TOP and LEFT elements of a div/span... how do I do that? I have tried:document.getElementById('out').top = x_coor;document.getElementById('out').style.top = x_coor;nothing works!!
document.getElementById('out').style.top = y_coor + "px";also don't forget to apply absolute posistion to 'out'.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...