To have something follow the mouse around the screen requires two things. The first is a function that uses whichever of the various ways that the particular browser supports to work out exactly where the mouse is within the browser viewport and the second is a function that repositions an element within your web page relative to that mouse position.
By using an event listener (or equivalent for IE8 and earlier) we can detect movements in the mouse and run the function that moves the div we have following the mouse without interfering with anything else that we may decide to do that involves detecting mouse movement. This also allows us to wrap our two functions inside of an anonymous function and so make the code almost completely unobtrusive. We just need to supply three parameters to that function in order to identify which div is to follow the mouse and the distance to the right and down the screen that the top left corner of the div is to be positioned relative to the mouse position.
This article written by Stephen Chapman, Felgall Pty Ltd.