Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here




Building the Better MouseOver with preloaders by carpeliam
Posted: 29 Jun 00

You might have noticed that on some pages with mouseOvers, it takes a little while for the graphic to download. I think that's ok for the first time, but when a request for the graphic is going back to the server every time I move my mouse, that's a problem. It's just downright annoying. What's the solution? "Preload" your graphics so they're already in cache when the visitor moves their mouse. That way, you avoid having to load it every single time. Here's a simple script for it:

    // declare new images
    var yourImageNormal = new Image();
    var yourImageOver = new Image();

    // assign image values
    yourImageNormal.src = "images/normal.gif";
    yourImageOver.src = "images/special.gif";

    function highlight (source) {
      document [source].src = eval(source + "Over.src");

    function dim (source) {
      document [source].src = eval(source + "Normal.src");
<A HREF="link.html" onMouseOver="highlight('yourImage')" onMouseOut="dim('yourImage')"><IMG SRC="images/normal.gif" NAME="yourImage" ALT="your image description" BORDER="0"></A>

Try that, see if it works. You'll probably see a lot of different mouseOver scripts floating around the web, but make sure yours is a preloading script.

Liam Morley

Back to HTML, XHTML & CSS FAQ Index
Back to HTML, XHTML & CSS Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close