The ImageLoader Utility allows you an alternate method of using CSS class names to load images.
Hover over each image to show its triggers and limit. Try tripping the triggers to see the load reactions. Refresh the page to reset the images.
Look familiar? These are the same images and triggers as the Basic Features example (with the weather image omitted). The only difference is the manner in which we're loading the images on the back end.
Insead of registering specific image ids/URLs with a group, you can simply tag the group with a CSS class. The group will later use this class name to identify which DOM elements belong to the group. Each group should have one corresponding class. Each class must have a
background:none CSS definition at the top of the page, as in this example:
Here is the HTML for the images:
A few things to note. First, the images have class names matching those in the style definitions above.
Second, the image URL is set in the
background-image of the elements. The
Third, since the
<img> element displays its images through the
background-image, its size won't change when the image is loaded. Therefore the
height needs to be set in the HTML. And since that gives the image a substantial size, the browsers would show a missing-image icon if the
src attribute were not specified. Therefore we need to set one; a transparent one so that the background image will show through.
This brings up an important limitation with this approach: you cannot alter the natural size of the image. Because the image is displayed as a background image, the browser will not resize the image according to the
height of the
Note that you are free to combine this class-name approach with the other. The same group can have some images identified by class name and others by registering ids/URLs.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.