Here again, we extend our base object imgmootater
.
And, again, the preparation for this recipe is the imgmootater
class itself. Sound the trumpets!
var imgmootater = new Class({ initialize: function() { this.imgs = $$('img'); }, make_titles: function() { this.imgs.each(function(el){ el.set('title',el.get('alt')); }); } });
Extend the imgmootater
class. Perhaps somewhat academically, we are extending something that already does an action we need. In this case, at least academically, we are demonstrating a recipe that shows that imgmootater
does a great deal of important, reusable work. In this example, what it does is duplicate the ALT attribute metadata into the TITLE
attribute so that mouse over shows the metadata.
The new implementation of the class will be called lazyloader
and will focus on IMG elements that have a place-holding image as their SRC. Add an onScroll
event to the window and bind to it the class function, which checks...