-
My name is Brad Harris, and I currently reside in the Abq, New Mexico area. I'm a web-developer, specializing in front-end development. PHP is my weapon of choice for the server side, but my creative side thrives on Javascript and CSS.
-
My Recent Ramblings
Tags
Archives
Monthly Archives: July 2008
Complex Javascript Event Handling: EventMediator
A large enterprise sized project I work on uses YUI library extensively, and events are a huge part of the rich front end we’re developing. What you start to learn quickly about UI events, is that dependencies between different events start to get very complicated very fast. When A depends on B, but [...]
Tagged javascript, yui 4 Comments
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.
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.
- First, I would need to listen to the load event of the image I was replacing the src of.
- 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);
Tagged javascript, jquery Leave a comment
Back to Firefox 2