views:

47

answers:

1

Hi, few questions, just wondering if anyone can help?

I have a table with 1 long row (1000 pixels) and one single column, how do i go about creating a method whereby when the mouse cursor is on the leftmost side of the cell, a variable, lets say X is set to 0, the further right the mouse cursor moves in the cell, the value of X increases.

I know that sounds like a strange question but im working on a project where this type of functionality is desired.

Is there a javascript method to create this feature?

Thanks for any help.

A: 

Is there a javascript method to create this feature?

Yes, there are things in JavaScript which can do what you want. Basically you need to put an "onmousemove" event on your table. The following will work for Firefox and Chrome:

<html>
<body>
<script>
function movedamouse (event)
{
var mytd = document.getElementById ("mytd");
myxpos = event.pageX;
mytext = document.createTextNode (myxpos);
while (mytd.firstChild)
mytd.removeChild (mytd.firstChild);
mytd.appendChild (mytext);
}
</script>
<table>
<tr>
<td>
bbaby
</td>
<td id="mytd" onmousemove="movedamouse(event)"
    style="width:1000px;background:chartreuse">
</td>
</tr>
</table>
</body>
</html>

I'll leave fixing this for Internet Explorer as an exercise. Also, the offset bit needs some work. Anyway this is just to illustrate the idea.

Kinopiko