<?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>Web Development Blog &#187; fade</title>
	<atom:link href="http://www.scriptiny.com/tag/fade/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptiny.com</link>
	<description>This web development blog features fresh articles on JavaScript, AJAX, CSS, XHTML, PHP, Photoshop and more.</description>
	<lastBuildDate>Fri, 10 Feb 2012 19:53:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>JavaScript Fade Tutorial &#8211; Fading Elements In/Out</title>
		<link>http://www.scriptiny.com/2011/01/javascript-fade-in-out/</link>
		<comments>http://www.scriptiny.com/2011/01/javascript-fade-in-out/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 05:01:32 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[fade]]></category>
		<category><![CDATA[fading]]></category>
		<category><![CDATA[tween]]></category>

		<guid isPermaLink="false">http://www.scriptiny.com/?p=382</guid>
		<description><![CDATA[One of the most common JavaScript effects is fading elements and text in and out. Fortunately, it isn't very difficult to script and doesn't require a JavaScript framework.]]></description>
			<content:encoded><![CDATA[<p>One of the most common JavaScript effects is fading elements and text in and out. Fortunately, it isn&#8217;t very difficult to script and doesn&#8217;t require a JavaScript framework. This tutorial walks through creating a well-coded standalone fading script.</p>
<p>To begin, let&#8217;s create a wrapper object for our functions. It will return two functions: an initialization function and a tween function that will handle the animation. For the init function, we will pass the ID of the element we want to animate as the first parameter. The second parameter will be a toggle (1 or -1) to determine the direction of the fade. The third will be the target (0-100) which will default to 0 or 100 based on the direction.</p>
<pre class="brush: jscript; title: ; notranslate">var fadeEffect=function(){
	return{
		init:function(id, flag, target){
		},
		tween:function(){
		}
	}
}();</pre>
<p>Now let&#8217;s fill in the first function&#8230;. here is a breakdown of the lines followed by the code:</p>
<ol>
<li>Create an object variable to reference the element we are fading</li>
<li>Clear any active fading on the element</li>
<li>Set the target opacity to the passed variable else check the direction to determine the default</li>
<li>Set the internal flag to 1 or -1 based on the boolean (0/1) passed as the parameter</li>
<li>Get the opacity off the DOM if available else assume it is 0 (for purposes of this demo)</li>
<li>Set the tween function to be executed every 20 milliseconds until cancelled</li>
</ol>
<pre class="brush: jscript; title: ; notranslate">this.elem = document.getElementById(id);
clearInterval(this.elem.si);
this.target = target ? target : flag ? 100 : 0;
this.flag = flag || -1;
this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
this.si = setInterval(function(){fadeEffect.tween()}, 20);</pre>
<p>Next we complete the tween function to update the opacity/alpha on the previously set interval.</p>
<ol>
<li>Check if the current opacity is equal to the target opacity</li>
<li>If previous is true clear the interval/exit</li>
<li>Else</li>
<li>Calculate the new opacity with easing (modify the &#8220;.05&#8243; value to control speed)</li>
<li>Divide the calculated value by 100 for standard CSS opacity (0-1)</li>
<li>Set the IE based opacity filter (0-100)</li>
</ol>
<pre class="brush: jscript; title: ; notranslate">if(this.alpha == this.target){
	clearInterval(this.elem.si);
}else{
	var value = Math.round(this.alpha + ((this.target - this.alpha) * .05)) + (1 * this.flag);
	this.elem.style.opacity = value / 100;
	this.elem.style.filter = 'alpha(opacity=' + value + ')';
	this.alpha = value
}</pre>
<p>And all together now&#8230;</p>
<pre class="brush: jscript; title: ; notranslate">var fadeEffect=function(){
	return{
		init:function(id, flag, target){
			this.elem = document.getElementById(id);
			clearInterval(this.elem.si);
			this.target = target ? target : flag ? 100 : 0;
			this.flag = flag || -1;
			this.alpha = this.elem.style.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
			this.si = setInterval(function(){fadeEffect.tween()}, 20);
		},
		tween:function(){
			if(this.alpha == this.target){
				clearInterval(this.elem.si);
			}else{
				var value = Math.round(this.alpha + ((this.target - this.alpha) * .05)) + (1 * this.flag);
				this.elem.style.opacity = value / 100;
				this.elem.style.filter = 'alpha(opacity=' + value + ')';
				this.alpha = value
			}
		}
	}
}();</pre>
<p>You can call the function like so:</p>
<pre class="brush: jscript; title: ; notranslate">fadeEffect.init('fade', 1, 50) // fade in the &quot;fade&quot; element to 50% transparency
fadeEffect.init('fade', 1) // fade out the &quot;fade&quot; element</pre>
<h3><strong><a href="http://sandbox.scriptiny.com/javascript-fading/">Click here</a></strong> for the demo.</h3>
<h3><strong><a href="http://sandbox.scriptiny.com/javascript-fading/fading.zip">Click here</a></strong> to download.</h3>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptiny.com/2011/01/javascript-fade-in-out/feed/</wfw:commentRss>
		<slash:comments>89</slash:comments>
		</item>
		<item>
		<title>JavaScript Color Fading Script</title>
		<link>http://www.scriptiny.com/2008/05/javascript-color-fading-script/</link>
		<comments>http://www.scriptiny.com/2008/05/javascript-color-fading-script/#comments</comments>
		<pubDate>Sat, 03 May 2008 03:05:52 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[fade]]></category>

		<guid isPermaLink="false">http://www.scriptiny.com/?p=36</guid>
		<description><![CDATA[This JavaScript color fading script allows for easy color transitions. Add fade effects to tables, divs and more. You can target an elements background, border or text color.]]></description>
			<content:encoded><![CDATA[<p><iframe src="http://sandbox.scriptiny.com/fader/fader2.html" width="459" height="114" scrolling="no" frameborder="0" name="js_fader"></iframe></p>
<p>This lightweight JavaScript allows for easy color transitions. Add fading effects to tables, divs and more. You can target an elements background, border or text color.</p>
<p>Below is the command to call the function.</p>
<pre class="brush: jscript; title: ; notranslate">colorFade('divid', 'background', 'ece7b4', 'f9bcbc', 25, 30)</pre>
<p>The first parameter is the id of the element you are targeting. The second is the property to fade which can be the background, border or text. The third is the hex value of the starting color. The third is the hex value to fade to. The fourth and fifth are both optional. The first is the the number of times to divide the color difference and the last is the transition speed.</p>
<p>This script has been tested in all major browsers and is available free of charge for both personal or commercial projects under the <a href="http://creativecommons.org/licenses/by/3.0/us/" target="_blank">creative commons license</a>. Community support is <a href="http://www.scriptiny.com/qa/">available here</a>. Paid support is also available, <a href="http://www.scriptiny.com/contact/">contact me</a> for details.</p>
<p><strong><a href="http://sandbox.scriptiny.com/fader/fader.html" target="_blank">Click here to view the demo.</a></strong></p>
<p><strong><a href='http://www.scriptiny.com/wp-content/uploads/2008/05/fader.zip'>Click here to download the script.</a></strong></p>
<p><strong>Update 5/5/2008</strong> &#8211; I have tweaked a few things and integrated some performance improvements based on Nate&#8217;s suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.scriptiny.com/2008/05/javascript-color-fading-script/feed/</wfw:commentRss>
		<slash:comments>89</slash:comments>
		</item>
	</channel>
</rss>

