Mootools Fx.Index v1.0

At work I needed to perform an animation on a sprite-based image (e.g. one large image containing multiple stages within an animation, pre-rendered). Since there was no easy way within Mootools to iterate over an array of class names, I created one. I called it “Fx.Index”, but if you have a better name for it, please leave me a comment.

Fx.Index = Fx.Base.extend({
initialize: function(el, css_classes, options) {
this.element = $(el);
this.css_classes = css_classes;
this.parent(options);
this.previous_index = null;
},
increase: function() {
var index = this.now.toInt();
if (this.previous_index == index)
return;
this.previous_index = index;
var klass = this.css_classes[index];
if ($chk(this.options.classBase))
klass += " " + this.options.classBase;

this.element.className = klass;
}
});

This code is taken straight from our product, which uses Mootools 1.11. So I’ll post an update once I port it to Mootools 1.2, at which point I’ll submit it to be added in the not-yet-created plugin directory.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s