<?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>Shaun Ambrose &#187; jquery</title>
	<atom:link href="http://www.shaunambrose.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shaunambrose.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 01 Apr 2012 04:21:42 +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>How to add a delay to a jQuery animation</title>
		<link>http://www.shaunambrose.com/2010/01/15/how-to-add-a-delay-to-a-jquery-animation/</link>
		<comments>http://www.shaunambrose.com/2010/01/15/how-to-add-a-delay-to-a-jquery-animation/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 21:41:32 +0000</pubDate>
		<dc:creator>Shaun</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.shaunambrose.com/?p=205</guid>
		<description><![CDATA[A couple of days ago, I was looking for a way to add a pause after an animation was triggered. This was before jQuery 1.4 was released. I found a couple of solutions including using the javascript function setTimeout or some people would imitate a delay by setting an animation for the desired number of [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago, I was looking for a way to add a pause after an animation was triggered. This was before jQuery 1.4 was released. I found a couple of solutions including using the javascript function setTimeout or some people would imitate a delay by setting an animation for the desired number of seconds that doesn&#8217;t change anything. Something like this&#8230;</p>
<p><span id="more-205"></span></p>
<pre>
<code>
$("#box1").fadeTo(1000, 0).fadeTo(3000, 0).fadeTo(1000, 1);
</code>
</pre>
<p>This will fade out an element in 1 second, then it will &#8220;pause&#8221; by setting another animation for 3 seconds that doesn&#8217;t change anything, then it will change it back to 100% opacity. It&#8217;s kind of an awkward way to do it.</p>
<p>But now with jQuery 1.4, things are a lot easier. You just need to just need to use the delay() function. Like so&#8230;</p>
<pre>
<code>
$("#box2").fadeTo(1000, 0).delay(3000).fadeTo(1000, 1);
</code>
</pre>
<div style="width:40px; height:40px; background:#c78b8b; border:1px solid #4f4f4f;" onclick="$(this).fadeTo(1000, 0).delay(3000).fadeTo(1000, 1);"></div>
<p>Click on the box and notice there is a 3 second delay after the box fades out, before it reappears. Visually, the effect looks exactly the same before the delay() function was introduced, but the code is nicer now.</p>
<p><br clear="none" />To set the delay before an animation fires, do this&#8230;</p>
<pre>
<code>
$("#box3").delay(3000).fadeTo(1000, .1);
</code>
</pre>
<p>Now there will be a 3 second delay before the box fades:</p>
<div style="width:40px; height:40px; background:#c78b8b; border:1px solid #4f4f4f;" onclick="$(this).delay(3000).fadeTo(1000, .1);"></div>
<p><br clear="none" />Or if you want to set the delay after an animation fires. Like a delay before your next lines of code are fired, do something like this&#8230; (I&#8217;m not sure if this is the best way, but it&#8217;ll work.)</p>
<pre>
<code>
$("#box4").fadeTo(1000, .1).delay(3000).fadeTo(1, .1);
</code>
</pre>
<p>And that&#8217;s all there is too it. To read more about the delay() function, <a href="http://api.jquery.com/delay/">check out the jQuery documentation.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shaunambrose.com/2010/01/15/how-to-add-a-delay-to-a-jquery-animation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

