Fx.Morph

Morphs an element to the properties of a specified className.

Fx.Morph = Fx.Styles.extend({
 
	start: function(className){
 
		var to = {};
 
		$each(document.styleSheets, function(style){
			var rules = style.rules || style.cssRules;
			$each(rules, function(rule){
				if (!rule.selectorText.test('\.' + className + '$')) return;
				Fx.CSS.Styles.each(function(style){
					if (!rule.style || !rule.style[style]) return;
					var ruleStyle = rule.style[style];
					to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
				});
			});
		});
		return this.parent(to);
	}
 
});
 
Fx.CSS.Styles = ["backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"];
 
Fx.CSS.Styles.extend(Element.Styles.padding);
Fx.CSS.Styles.extend(Element.Styles.margin);
 
Element.Styles.border.each(function(border){
	['Width', 'Color'].each(function(property){
		Fx.CSS.Styles.push(border + property);
	});
});
 
var myMorph = new Fx.Morph('morpher', {wait: false});
 
$('morph1').addEvent('click', function(e){
	new Event(e).stop();
 
	myMorph.start('morph1');
 
});
 
$('morph2').addEvent('click', function(e){
	new Event(e).stop();
 
	myMorph.start('morph2');
 
});
<a href="#" id="morph1">morph to morph1</a> | <a href="#" id="morph2">morph to morph2</a>
 
<div id="morpher" class="morph1">
	Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
.morph1 {
	color: #666;
	background-color: #ccc;
	height: 200px;
	width: 300px;
	font-size: 15px;
	overflow: hidden;
	opacity: 1;
	border: 2px solid #aaa;
	margin: 0;
	padding: 5px;
}
 
.morph2 {
	color: #000;
	background-color: #ff3300;
	height: 100px;
	width: 400px;
	font-size: 10px;
	opacity: 0.7;
	margin: 60px;
	padding: 60px;
	border: 10px solid #000;
}
morph to morph1 | morph to morph2
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.