O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Extending images—lazy load

Here again, we extend our base object imgmootater.

Getting ready

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'));
});
}
});

How to do it...

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required