Jump to content

[SOLVED] relative to mouse position?


Stickybomb

Recommended Posts

i am trying to write a script that displays a div relative to where yor mouse is located when you mouse over a link

 

this is the code i put together

 

<script type="text/javascript">

	function getX(){
	var xpos;
	xpos=event.clientX;

	return xpos;
	}

	function getY(){
	var ypos;
	ypos=event.clientY;

	return ypos;
	}

	function show(pop_id){
	var img,popup;
	img="fig"+pop_id;
	popup=document.getElementById(img);
	popup.style.visability='visible';
	popup.style.top=getX();
	popup.style.left=getY();
	}

	function hide(pop_id){
	var img,popup;
	img="fig"+pop_id;
	popup=document.getElementById(img);
	popup.style.visability='hidden';
	}

	</script>

 

this is the html i am using to call the script

 

<a href="#" class="pop" onmouseover="show(1);" onmouseout="hide(1);">Figure 1</a>

 

its been a while since i messed with javascript and i can't seem to get this to work i basically took the code directly from the w3schools example i fund while doing a search on the subject. Any help is appriciated.

Link to comment
https://forums.phpfreaks.com/topic/47797-solved-relative-to-mouse-position/
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.