[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

track a mouse

I want to move a <DIV> to a place where a mouse was clicked.How do I do that?
0
Moshe072898
Asked:
Moshe072898
1 Solution
 
xabiCommented:
Hi there:

-------- 8< ------- 8< -----
<html>
<head>
<SCRIPT LANGUAGE="JavaScript1.1">
<!--
initialized = false
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
if (ie4) {
      if (navigator.userAgent.indexOf('MSIE 5')>0) {
            ie5 = true;
      } else {
            ie5 = false; }
} else {
      ie5 = false;
}

function press(e) {
  if (initialized) {
        if (ns4) {x=e.pageX; y=e.pageY;}
        if (ie4) {x=event.x; y=event.y;}
        if (ie5) {x=event.x+document.body.scrollLeft; y=event.y+document.body.scrollTop;}
        if (ie4) {
          blockDiv.style.left = x
          blockDiv.style.top = y
        } else {
          document.blockDiv.left = x
      document.blockDiv.top = y
    }
  }
  return true
}

function init() {
      initialized = true
}

document.onmousedown=press
if (ns4) window.captureEvents(Event.MOUSEDOWN)
window.onmousedown=press
//-->
</script>
</HEAD>
<BODY onload="init()">
<DIV ID="blockDiv" STYLE="position:absolute; left:50px; top:100px;">
Click<br>
Click
</DIV>
</body>
</html>
----- 8< -------- 8< ----

xabi
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now