Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] An easy one for the experts :-)


  • From: javascript@xxxxxxxxxx (javascript@xxxxxxxxxx)
  • Subject: [Javascript] An easy one for the experts :-)
  • Date: Thu, 20 Dec 2001 14:26:45 -0100

Hi,

I have searched the manuals .. on google .. in archives ... without luck.

Consider this piece of code:

<html><head><title>Test</title>
<script>
function position(event)
{
        cursor.style.posLeft=board.style.posLeft+event.x;
        cursor.style.posTop=board.style.posTop+event.y;
}
</script>
</head>
<body>
<p><img id="board" width="320" height="320" src="board.gif" style="position:relative;" onClick="position(event)">
<img id="cursor" src="cursor.gif" style="position:absolute">
</body>
</html>

Purpose:

- whenever a mouse click is detected on board move the cursor to this position.

Problem:

- although the code works (!) the cursor is misaligned.  That is, it is positioned something like 5 pixels to the left of the click and 5 pixels above the click.    I've tried to use pageXOffset and pageYOffset to adjust the cursor - but I guess they're only good when scrollbars are involved.


How do I solve this?   I know I can set position:absolute et al on the board, but this is not acceptable ...

I'm mainly targeting IE but, if at all possible, would like to see a cross-browser solution :-)


Merry Christmas,

Brian