Skip to content

Instantly share code, notes, and snippets.

@arian
Created August 22, 2010 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arian/543599 to your computer and use it in GitHub Desktop.
Save arian/543599 to your computer and use it in GitHub Desktop.
// Cleaned up version of Elements.MultiHighlight.js - http://github.com/subhaze/mootools-elements-multihighlight/blob/master/Source/Elements.MultiHighlight.js
/*
- No need for the this.each
- mouseoverVals and mouseoutVals are no object values of another object anymore (better minification)
- Set the mouseoverVals and mouseoutVals in the mouseenter event (the properties might change after the first call)
if (backgroundColor || foregroundColor){ ... to if (!backgroundColor && !foregroundColor) return this;
- applied MooTools coding style
*/
/*
---
name: Elements.multiHighlight
description:
license: MIT-style
requires:
- Core/Elements
- Core/Fx.Morph
provides: Elements.multiHighlight
authors: [Michael Russell]
...
*/
Elements.implement({
multiHighlight: function(backgroundColor, foregroundColor, morphProps){
var mouseoverVals = {}, mouseoutVals = {};
if (!backgroundColor && !foregroundColor) return this;
if (morphProps) this.set('morph', morphProps);
this.addEvents({
'mouseenter': function(e){
if (backgroundColor){
mouseoutVals['background-color'] = elem.getStyle('background-color') != 'transparent' ?
elem.getStyle('background-color') : '#fff';
mouseoverVals['background-color'] = backgroundColor;
}
if (foregroundColor){
mouseoutVals['color'] = elem.getStyle('color');
mouseoverVals['color'] = foregroundColor;
}
e.target.morph(mouseoverVals);
},
'mouseleave': function(e){
e.target.morph(mouseoutVals);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment