Tag Archives: jquery

YUI => jQuery?

Recently a question was posted on Quora, “How could YUI3 improve its image compared to jQuery, MooTools, etc.?“. John Resig, of jQuery fame, gave a great answer on his thoughts to the question. Nicholas Zakas responds with another great explanation of why he doesn’t think the comparison is needed. Both have great points, and are [...]

Also tagged , | Leave a comment

Subscribing to an image loaded event

I recently was working on something where I needed to swap the src of an image, but then perform some specific javascript AFTER the new image was loaded, namely resize the dimensions a little. This may seem pretty simple, but took me a little research, along with trial and error to get a working solution, so hopefully it helps someone else. I often use jQuery on my smaller projects, so I’ll show how I accomplished this with that toolkit.

  1. First, I would need to listen to the load event of the image I was replacing the src of.
  2. Next, in order to trigger the handler, we need to actually change the src of the image
$('#my-image').load(function() {
    //Logic for w/e here, resizing, etc.
}).attr('src', myNewImageSrc);

The code itself is really simple, but it took me a few to realize that jQuery solved the problem by simply letting us listen to the load event of the image, and count on it being fired when the src changes, and finishes loading.

Also tagged | Leave a comment

Simple jQuery image rollover script

Just a simple script I use to automate image rollovers that may be of use to others. Just include this javascript: UPDATED I felt motivated to simplify this even more according to many of the comments below. This takes advantage of html5 data attributes instead of a custom one, and eliminates the need for a [...]

Also tagged | 54 Comments

Page optimized by WP Minify WordPress Plugin