Jump to content

Position over button


Canman2005

Recommended Posts

Hi all

 

I have a form button which looks like

 

<input type="image" src="images/longbar.gif" width="400" height="30"

 

What I want to try and do is to display (as HTML text) above this button what position the mouse is within the button, so having a number chart going from 1.0  1.1  1.2 .... upto...... 9.8  9.9  10.0

 

So if someone put their mouse in the middle of this button, it would display 5.0 and if they place it at a 1/4 of the way along, it woud display 2.5 and so on.

 

Is this possible? Can anyone help me? I'm a total ZERO when it comes to JScripting, so could really do with a hand.

 

Thanks very very very much

Link to comment
https://forums.phpfreaks.com/topic/134652-position-over-button/
Share on other sites

Okay, I have managed to track down and mod a script, it's

 

<script type="text/javascript">

var posx;

function getMouse(e){

posx=0;

var ev=(!e)?window.event:e;//IE:Moz

if (ev.pageX){//Moz

posx=ev.pageX+window.pageXOffset;

}

else if(ev.clientX){//IE

posx=ev.clientX+document.body.scrollLeft;

}

else{return false}//old browsers

document.getElementById('myspan').firstChild.data='X='+posx;

}

document.onmousemove=getMouse

</script>

<span id="myspan"> </span>

 

This seems to give the X coordinates, but I am having problems doing two things;

 

1: Attaching it to a form button, so that it only read the X coordinates on that button

 

2: Also, if you move you mouse quickly from right to left, rather than X coordinate resetting back to 0, it seems to stay on higher numbers, for example, I moved the mouse very fast from right to left and it went from a X coordinate count on the far right of 987 to 123 when it was as far left as it could be. Any reason for that?

 

Any help would be appricated everyone

Link to comment
https://forums.phpfreaks.com/topic/134652-position-over-button/#findComment-701131
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.