Jump to content

I want to move a div according to client's mouse X,Y


Betty_S

Recommended Posts

Hi folks!I want to move a div according to client's mouse X,Y so I wrote that:

<script>function mouseXY(){var X = event.clientX;var Y = event.clientY;document.getElementById("movingDiv").style.top=X;document.getElementById("movingDiv").style.left=Y;}window.onload=mouseXY;</script></head><body onmousemove="java script:mouseXY();"> <div id="movingDiv" style="top=0;left=0;position:absolute;border-color:#000000;border:groove;width:250px;height:96px;background-color:#CCCCCC" onClick="java script:this.style.display='none';"></body>

Well, the div moves but its not attached to the mouse X and Y.What can I do? :) Thanks.

Link to comment
Share on other sites

???
I believe MrAdam means:
<script>function mouseXY(e){// so that it'll work in DOM compliant browsers as well as IEe = (e) ? e : window.event;  var X = e.clientX;var Y = e.clientY;document.getElementById("movingDiv").style.top=X;document.getElementById("movingDiv").style.left=Y;}window.onload=mouseXY;</script></head><body onmousemove="mouseXY(event);">

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
×
×
  • Create New...