Archive for the 'js' Category

Alternating row colors and adding hover with javascript

Saturday, December 16th, 2006

Keeping in my do-it-all-with-javascript theme, here’s something else I created in order to keep the javascript completely separate from the HTML from the more javascript stuff.

It was originally created for the purposes of adding the hover onmouseover, but I also decided to add the alternating row color at the same time.

To be completely anal, I’ll note that the hover is something that should be done with javascript (it pretty much has to be done in javascript anyways, and it’s less part of the presentation than an action), while the alternating colors should be purely CSS.

However, this makes page creation easier. I also remember having some problems with reading the background color style from the row object, so this makes it easy.
(more…)

automatic, more semantic image hovering

Wednesday, December 13th, 2006

I can’t stand editing pages with those hard-coded, god-forsaken [img onmouseout=”MM_replace(…);” onmouseover=”MM_Replace(…)” … ] tags. I don’t mind throwing a little javascript into the midst of my HTML document, but that’s just excessive, and entirely too static, too. Making an image hover should not be that difficult.

So I came up with this quick hack that should probably be fleshed out a lot more. Basically, you set up the image as you normally would, but give it a special class and a sort-of special name. Once the page is loaded, javascript looks through for all images with that class, uses the .src to figure out the name of the hovered version, preloads it (for caching), and attaches the requisite onmouseover and onmouseout events.

(more…)