1. Home
  2. Computing & Technology
  3. JavaScript

Follow the Mouse

2. Obtain the Script

clr gif
Join the Discussion

Questions? Comments?

More of this Feature

Introduction Add to Your Page

To set up this effect the first thing that you need to do is to copy the script and attach it to the head of your page.

You next attach the script into your web page by adding the following code into the head section of your page.

<script type="text/javascript" src="follow.js">
</script>

There are three variables that you can custimize at the top of the script.

  • divName - this is the id of the div on your page that is the object that is to follow the mouse. We'll code the actual contents of the object that is to follow the mouse into this div later.
  • offX and offY are the distance to the right and down from the current mouse cursor position where the top left corner of the object is to appear.

The final step is to add the object to your page.

Sample Page | Obtain the Script | Add to Your Page

Explore JavaScript

More from About.com

  1. Home
  2. Computing & Technology
  3. JavaScript

©2008 About.com, a part of The New York Times Company.

All rights reserved.