The hardest parts of getting an object to follow the mouse around the screen are:
- Finding the position of the mouse in different browsers
- Figuring out where to place the object relative to the mouse and the edge of the window.
We can solve the first of these by creating a couple of functions that will examine the various places where the mouse position is stored in the different browsers and extract that position from whichever place it finds it in. The simplest solution to the second is to just position the object so that it is always in the same place relative to the mouse and ignores the problem of it disappearing out of the window.
We'll begin by taking a look at a simple text object that follows the mouse around the page.