<?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>CoryMathews.com &#187; jQuery</title>
	<atom:link href="http://corymathews.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://corymathews.com</link>
	<description>Things I should remember and then some...</description>
	<lastBuildDate>Wed, 04 Aug 2010 18:32:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>jQuery Animation</title>
		<link>http://corymathews.com/514/jquery-animation/</link>
		<comments>http://corymathews.com/514/jquery-animation/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 17:17:02 +0000</pubDate>
		<dc:creator>CoryMathews</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://corymathews.com/?p=514</guid>
		<description><![CDATA[I was recently working with the .animate() function and found there are some really cool effects you can create with it. However the more I used it the more problems I ran into. Basic usage of .animate() Just for good measure here is the basic usage of the .animate() function. I won&#8217;t go to far into [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently working with the .animate() function and found there are some really cool effects you can create with it. However the more I used it the more problems I ran into.</p>
<p><strong>Basic usage of .animate()</strong></p>
<p>Just for good measure here is the basic usage of the .animate() function. I won&#8217;t go to far into this, check out the <a title="jQuery API Animate" href="http://api.jquery.com/animate/">jQuery API for more</a>.</p>
<pre name="code" class="html">$("#SomeID").animate({ width: '50px' }, { duration: 500 });</pre>
<p>This animates the id SomeID to a width of 50px over 500 milliseconds with a basic linear slide transition.</p>
<p><strong>The &#8220;animation&#8221; queue.</strong> (or so I will call it)</p>
<p>When jquery runs the .animate() function it runs it along side other javascript. This allows me to add multiple animations to a queue and then run one after another instead of all at the same time. For example</p>
<pre name="code" class="html">
$("#SomeID").animate({ width: '50px' }, { duration: 500 });
$("#SomeID").animate({ width: '150px' }, { duration: 500 });
$("#SomeID").animate({ width: '50px' }, { duration: 500 });
$("#SomeID").animate({ width: '150px' }, { duration: 500 });
</pre>
<p>This code will animate an id from a width of 50px to 150px to 50px to 150px one after another so I see a nice smooth slide from one stage to the next.</p>
<p>Now this code.</p>
<pre name="code" class="html">
$("#SomeID").animate({ width: '50px' }, { duration: 500 });
$("#SomeID").animate({ width: '150px' }, { duration: 500 });
$("#SomeID").animate({ width: '50px' }, { duration: 500 });
$("#SomeID").animate({ width: '150px' }, { duration: 500 });
alert('hi');
</pre>
<p>Notice the alert appears to run first. This <a href="http://stackoverflow.com/questions/1667757" target="_blank">got me</a> until I stopped to really think about the animation queue.</p>
<p>Take a look at this example from <a href="http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup" target="_blank">learning jquery</a></p>
<pre name="code" class="html">
$(document).ready(function() {
  $('ul.anim_queue_example1 a').hover(function() {
    $(this).animate({ left: 20 }, 'fast');
  }, function() {
    $(this).animate({ left: 0 }, 'fast');
  });
});
</pre>
<p>This is a simple hover effect for a list menu. The problem may not be easily spotted at first but try it out. Running your mouse over the menu quickly will cause the queue to fill up with animations and continue running them long after you stop. More then likely not the desired effect.</p>
<p><a href="http://brandonaaron.net/" target="_blank">Brandon Aaron</a> was easily able to fix this by adding a simple .stop() to the functions.</p>
<p>This now gives you this code</p>
<pre name="code" class="html">
$(document).ready(function() {
  $('ul.anim_queue_example2 a').hover(function() {
    $(this).stop().animate({ left: 20 }, 'fast');
  }, function() {
    $(this).stop().animate({ left: 0 }, 'fast');
  });
});
</pre>
<p>Adding the .stop() function will stop the current animation in the queue before running the next animation and will fix the problem.</p>
<p>Ok, now for the example problem that does not get fixed by calling .stop().</p>
<p>For the next example I am going to be using the<a href="http://blog.mythin.net/file_download/5" target="_blank">pause plugin</a> by Johnathan Howard and posted below</p>
<pre name="code" class="html">
$.fn.pause = function(milli) {
  milli = milli || 1000;
  return this.queue("fx",function(){
    var self = this;
    setTimeout(function(){$.dequeue(self);},milli);
  });
};
</pre>
<p>Now check out the following:</p>
<pre name="code" class="html">
$("#SomeID, #SomeID2").animate({ width: '50px' }, { duration: 500 }).pause(350);
$("#SomeID, #SomeID2").animate({ width: '150px' }, { duration: 500 });
$("#SomeID, #SomeID2").animate({ width: '50px' }, { duration: 500 }).pause(350);
$("#SomeID, #SomeID2").animate({ width: '150px' }, { duration: 500 });
$("#someID3").hover(function() {
$("#SomeID , #SomeID2").stop().height(50).width(50).animate({ width: '150px' }, 500);
} , function() {
$("#SomeID ").stop().animate({ width: '50px' }, 200);
$("#SomeID2").stop().animate({ width: '50px' }, 200);
});
</pre>
<p>This example will stop the current animation but when that short pause ends it will continue with the queue and mess with the desired animated effects. To stop this problem is actually pretty easy. To solve it change .stop() to .stop(true, false). This is because in .stop(true, false) the first true is the clearQueue parameter. This will clear all queued actions for the object. Meaning that all the future animations, once delayed, are now removed and will not interfere with the hover event.</p>
<p><strong>More problems</strong></p>
<p>1 more problem I have not looked into solving put probably will have to eventually is the problem of keeping those animations until after the hover is finished. Not every time will I want to completely clear the queue. I could see it being likely that I would want to do something more like the following:</p>
<pre name="code" class="html">
$("#someID3").hover(function() {
$("#SomeID , #SomeID2").pauseQueue().animate({ width: '150px' }, 500);
} , function() {
$("#SomeID , #SomeID2").stop().animate({ width: '50px' }, 200).startQueue();
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://corymathews.com/514/jquery-animation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Letting Google Load jQuery&#8230; The Right Way</title>
		<link>http://corymathews.com/517/letting-google-load-jquery-the-right-way/</link>
		<comments>http://corymathews.com/517/letting-google-load-jquery-the-right-way/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 00:23:42 +0000</pubDate>
		<dc:creator>CoryMathews</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://corymathews.com/?p=517</guid>
		<description><![CDATA[For some time now I have been letting google load the jQuery and jQuery UI libraries for me. There are many benefits to it which I will not get into, you can read more reasons to use it elsewhere. However I did notice something worth posting. You may be loading the jQuery library like so: [...]]]></description>
			<content:encoded><![CDATA[<p>For some time now I have been letting google load the jQuery and jQuery UI libraries for me. There are many benefits to it which I will not get into, you can read more reasons to use it elsewhere. However I did notice something worth posting.</p>
<p>You may be loading the jQuery library like so:</p>
<pre class="html">&lt;script src="http://jqueryjs.googlecode.com/files/jquery-1.4.2.min.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
<p>Well if you are then <strong>you are doing it wrong</strong>.</p>
<p>It was ySlow that told me why. Try changing that one line to the following and take another look at ySlow.</p>
<pre class="html">&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;</pre>
<p>Notice the difference? <strong>Google is now gzipping the library</strong> when its called from googleapis.com instead of googlecode.com thus lowering the files size drastically.</p>
<p>For those of us that are to lazy to try it out here is the result with the googleapis.com loaded instead of the googlecode.com.</p>
<p><a href="http://corymathews.com/wp-content/uploads/2009/12/jQueryLoading.gif"><img class="aligncenter size-medium wp-image-520" title="jQueryLoading" src="http://corymathews.com/wp-content/uploads/2009/12/jQueryLoading-300x27.gif" alt="jQueryLoading" width="300" height="27" /></a></p>
<p>You can see instead of downloading 57.2kb that you would with the googlecode file the gzip compression brings it down to 19kb.</p>
<p>The same rule would apply for other<a href="http://code.google.com/apis/ajaxlibs/documentation/#AjaxLibraries"> libraries that are hosted by google</a>. such as mootools, or even the jQuery UI.</p>
<p>So next time you go to include the library make sure to do it the right way.</p>
<p>Now I just need to switch all the sites I have that are using it.. such as this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://corymathews.com/517/letting-google-load-jquery-the-right-way/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rounded Corners using jQuery</title>
		<link>http://corymathews.com/348/rounded-corners-using-jquery/</link>
		<comments>http://corymathews.com/348/rounded-corners-using-jquery/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 03:37:36 +0000</pubDate>
		<dc:creator>CoryMathews</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://corymathews.com/?p=348</guid>
		<description><![CDATA[jQuery is slowly changing the way web designers and developers create web sites. Here is an extremely easy way to achieve rounded corners using jQuery. You can view live demos on iSearchNotes.com or at the plug-in webpage. In order to create our rounded corners you will of course first need jQuery. If you do not already [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery is slowly changing the way web designers and developers create web sites. Here is an extremely easy way to achieve rounded corners using jQuery.</p>
<p>You can view live demos on <a href="http://www.isearchnotes.com/" target="_blank">iSearchNotes.com</a> or at the <a href="http://www.malsup.com/jquery/corner/" target="_blank">plug-in webpage</a>.</p>
<p>In order to create our rounded corners you will of course first need jQuery. If you do not already have jQuery hurry up and go download it at <a href="http://www.jquery.com" target="_blank">jquery.com</a>. I will wait.</p>
<p>Waiting&#8230;</p>
<p>Ok so now you will also need to download the rounded corners plug-in. This small jQuery script can be downloaded by saving this file <a href="http://www.malsup.com/jquery/corner/jquery.corner.js" target="_blank">jquery.corner.js</a></p>
<p>Now we have all that will will need to round those corners. On the page you wish to have the rounded corners on you must add includes to both javascript files.</p>
<pre name="code" class="html">&lt;script type="text/javascript" src="js/jquery.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/jquery.corner.js"&gt;&lt;/script&gt;</pre>
<p>Now we must tell jQuery which areas of the layout to round.</p>
<pre name="code" class="javascript">&lt;script type="text/javascript"&gt;
$(function(){
$("#content").corner()
});
&lt;/script&gt;</pre>
<pre name="code" class="html">&lt;div id="content"&gt;Hello this would have rounded corners&lt;/div&gt;</pre>
<p>This simply uses <a title="jQuery Selectors" href="http://docs.jquery.com/Selectors">jQuery&#8217;s selectors</a> to select the id content and rounds all 4 of that divs corners by the default amount.</p>
<p>This plug-in can do so much more then this example. You can pick which corners to round, how much to round by, how to round, and much, much, more. Instead of listing them all check out the <a href="http://www.malsup.com/jquery/corner/">plug-in page</a> to see more uses of it. (there are some pretty cool ones near the bottom of the page)</p>
<p>There are many different ways to use it but some of the more common uses would be:</p>
<pre name="code" class="javascript">
	$("#content").corner()
	$("#content").corner("bottom");
	$("#content").corner("top");
</pre>
<p>You could always avoid javascript altogether and do it the <a href="http://www.osguide.net/Tutorials/tutorial.php?p=4">hard way using css</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://corymathews.com/348/rounded-corners-using-jquery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
