<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Christian Albrecht &#187; jQuery</title>
	<atom:link href="http://christian-albrecht.info/index.php/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://christian-albrecht.info</link>
	<description>Freier Webentwickler</description>
	<lastBuildDate>Sat, 19 Jun 2010 10:21:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>jQuery fx stepper for css classnames</title>
		<link>http://christian-albrecht.info/index.php/2010/04/29/jquery-fx-stepper-for-css-classnames/</link>
		<comments>http://christian-albrecht.info/index.php/2010/04/29/jquery-fx-stepper-for-css-classnames/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 12:58:17 +0000</pubDate>
		<dc:creator>Christian Albrecht</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://christian-albrecht.info/?p=70</guid>
		<description><![CDATA[There are several solutions out there, for animating colors with jQuery, they tended to be slow for me so i made it via css classes: First the stepper This simply adds the given fx.end.name to the given elements classes, if not existing and appends the count of steps to the classname. The fx.state is a [...]]]></description>
			<content:encoded><![CDATA[<p>There are several solutions out there, for animating colors with jQuery, they tended to be slow for me so i made it via css classes:</p>
<h4>First the stepper</h4>
<p>This simply adds the given <var>fx.end.name</var> to the given elements classes, if not existing and appends the count of steps to the classname. The <var>fx.state</var> is a float between 0 and 1 and is multiplied with <var>fx.end.steps</var> which you give to the animation as you will see downwards.</p>
<pre class="syntax chili-lang-javascript">
$.fx.step['class+'] = function(fx){
    var r = RegExp(fx.end.name + '\\d*','g');
    if( !r.test(fx.elem.className) ) {
        fx.elem.className += ' ' + fx.end.name;
    }
    fx.elem.className = fx.elem.className.replace(
        r, fx.end.name + parseInt( fx.end.steps * fx.state )
    );
}

$.fx.step['class-'] = function(fx){
    if( fx.state == 1 ) {
        fx.elem.className = fx.elem.className.replace(
            RegExp(fx.end.name + '\\d*','g'),''
        );
    }
    fx.elem.className = fx.elem.className.replace(
        RegExp(fx.end.name + '\\d*'),
        fx.end.name + parseInt( fx.end.steps - fx.end.steps * fx.state )
    );
}
</pre>
<h4>Second the css classes</h4>
<p>You would generate them with any color blender available in the wild. I extended <a href="http://meyerweb.com/eric/tools/color-blend/">this</a> one by Eric Meyer to get 100 shades.</p>
<pre class="syntax chili-lang-css">
.hl0 { color: #000000; }
.hl1 { color: #030303; }
.hl2 { color: #050505; }
.hl3 { color: #080808; }
…
.hl93 { color: #EDEDED; }
.hl94 { color: #F0F0F0; }
.hl95 { color: #F2F2F2; }
.hl96 { color: #F5F5F5; }
.hl97 { color: #F7F7F7; }
.hl98 { color: #FAFAFA; }
.hl99 { color: #FCFCFC; }
.hl100 { color: #FFFFFF; }
</pre>
<h4>Third the usage</h4>
<p>Now you can play with your css class stepper, that should be pretty self-explaining, the counterpart to this example is the &#8216;class-&#8217; stepper.</p>
<pre class="syntax chili-lang-javascript">
$('.query').animate({
    'class+':{ 'name':'hl', 'steps':100 }
},{
    'duration':400, 'queue':0
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://christian-albrecht.info/index.php/2010/04/29/jquery-fx-stepper-for-css-classnames/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

