consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

A Coder's Notes

Email :
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull

Get connected and Online Tottington
remote management Makerfield code and design Aspull

Position Element Next To Mouse - CSS Javascript - 15/04/2013

Sometime you may wish to place an element, ie an image or a div, next to where the mouse is.

Starting in the <head> section of the page add the following...

function mymouseover(thisimg)
var e = window.event;
var posX = e.clientX;
var posY = e.clientY;

document.getElementById('my_element').style.left = posX + 'px' ;
document.getElementById('my_element') = posY + 'px' ;

What's going on? PosX and PosY are the actual position of the mouse. Now you've found the position of the mouse we set our element to position itself to that of the mouse!

Post A Comment

Name Comment
programming services specialist
Valid XHTML 1.0 Transitional