Mootools: Cache your effects

by brunofig 12. June 2007 13:57

When using the mootools shortcut

var myEffects = $(myElement).effects({duration: 1000, transition: Fx.Transitions.Sine.easeInOut});

that is always creating a new Fx.Styles instance, I decided to build a cache object.

What it does is returns a new Fx.Styles if none is found for the html element passed to the create method, caching it, for later reference.

var fxCache = {    cache:{},    options:{duration:300,transition:Fx.Transitions.Circ.easeInOut},    create: function (element,options)    {        element = $(element);        if (this.cache[element.id] == null)        {            return this.cache[element.id]=element.effects($merge.apply(null, [this.options].extend(options||{})));        }        else        {            return this.cache[element.id];        }    }}

Simply use it like so:

var fxA = fxCache.create("myHtmlElement",{"duration":600});var fxB = fxCache.create($("otherHtmlElement"));

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.7
Theme by Mads Kristensen

About the author

Hi!

My name is Bruno and I'am a senior consultant. When I'm not working, you can catch me playing with my daugther, taking pictures and hanging out with my friends. :)

Page List

Most comments

Root Server Root Server
1 comments
de Germany
steph steph
1 comments
sg Singapore

RecentComments

Comment RSS