I’m going to kick off a new weekly series this week I’m calling “The Basics”; Here’s the idea:
Every time I need to write some JavaScript for feature X on a new site I’m building, I always just go back to the last site I remember writing feature X for, pull off the code, make some tweaks, and incorporate it into the new site. This works fine, but it takes a little work each time, and I wind up with twenty copies of feature X floating around.
Over time, I might pick up a new technique that helps me solve feature X in a better way, but I’m not going to go back over twenty different sites and figure out how to massage the improvement into each one’s code.
So, the idea behind The Basics is that, once a week, I’ll take one of these common tasks, bundle it up into a reusable script, and put it here for everyone to use. Over time, we’ll build up a handy little javascript library.
There are lots of javascript libraries to take care of most of these, but many of them either don’t work cross-platform, are poorly documented, degrade poorly, or are hard to modify. So here are the ground rules for these scripts:
For the first week, I’m starting off with an easy one, but one that gets used all the time: image rollovers. We’ve been doing these since M.C. Hammer was cool and Netscape roamed the earth, but here’s the no-fuss 2006 approach.
You should check out JSAN, "a comprehensive resource for Open Source JavaScript libraries and software." The basic idea is very similar to what you've outlined here. They've developed decent distribution, testing, and packaging systems for JavaScript code. Perlcast recently had a very interesting interview with Casey West about JSAN, which I highly recommend.
Ok, I have two suggestions
Instead of using class="rollover" consider diffrent aproach. Make a specific image file name ex. "rollover-myimage_on.jpg" and scan img DOM tree for rollover*, build and array and cache images, then add rollover magic to this images.
What about three state rollovers? Example - I want to simulate classic button with trhee states: normaln, mouse over, clicked.
Great, this will be part of the new software for my comic cover gallerie.
My suggestion: include a "IE PNG-transparent problem fix"