<?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>WebMuch &#187; JavaScript</title>
	<atom:link href="http://webmuch.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://webmuch.com</link>
	<description>Everything about the web</description>
	<lastBuildDate>Tue, 16 Feb 2010 10:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Image Flip Using jQuery</title>
		<link>http://webmuch.com/image-flip-using-jquery/</link>
		<comments>http://webmuch.com/image-flip-using-jquery/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 00:11:42 +0000</pubDate>
		<dc:creator>Aayush</dc:creator>
				<category><![CDATA[JavaScript & AJAX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://webmuch.com/?p=175</guid>
		<description><![CDATA[<img src="http://webmuch.com/wp-content/uploads/2009/06/intro.jpg" alt="Image Flip Using jQuery Introduction Image" title="Image Flip Using jQuery Introduction Image" width="150" height="150" class="alignnone size-full wp-image-189" />In this week's post we will be creating an illusion effect of an image flip using jQuery of course. This thing can be used as a cool gallery kind of a thing. So, hopefully you guys will like it, let's get to it.]]></description>
			<content:encoded><![CDATA[<p>Alright, first of all this is not a real image flip but sort of an illusion, the image does not flip itself in 3D since jQuery does not provide us with an image rotation or a distort feature for HTML elements. I know their are some image rotation plug-ins out their but they don&#8217;t work out very well with animate method of jQuery.</p>
<h3>Preview:</h3>
<p><img src="http://webmuch.com/wp-content/uploads/2009/06/preview.jpg" alt="Image Flip Using jQuery Preview Image" title="Image Flip Using jQuery Preview Image" width="585" height="400" class="alignnone size-full wp-image-188" /><br />
<strong>Note: Image flip with reflection is for demo purposes only, it&#8217;s done using the PHP GD Library and it&#8217;s source files are also included in the source code, so meddle with them if you like.</strong></p>
<p><strong><a href="http://webmuch.com/demos/image_flip_demo/flip.html" alt="First Demo">DEMO-1</a> | <a href="http://webmuch.com/demos/image_flip_demo/vertical_flip.html" alt="Second Demo">DEMO-2</a></strong></p>
<h3>HTML Code:</h3>
<pre class="code">
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head>
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
&lt;title>Image Flip Illusion Using jQuery&lt;/title>
&lt;link rel="stylesheet" type="text/css" href="default.css" />
&lt;/head>

&lt;body>
&lt;div id="container">
	&lt;h1>Image Flip Illusion Using jQuery&lt;/h1>
    &lt;img id="image1" src="images/image1.jpg" />
    &lt;img id="image2" src="images/image2.jpg" />
&lt;/div>
&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js">&lt;/script>
&lt;script type="text/javascript" src="hflip.js">&lt;/script>
&lt;/body>
&lt;/html>
</pre>
<h3>CSS Code:</h3>
<pre class="code">
body{
	background-color:#000;
}
h1{
	color:#FFFFFF;
	font-family:Arial;
	font-size:24px;
	font-weight:bold;
}
#container{
	width:400px;
	margin:0px auto;
	height:380px;
	margin-top:50px}
#image1{
	position:absolute;
	cursor:pointer;
	width:300px;
	height:190px;
}
#image2{
	display:none;
	position:absolute;
	cursor:pointer;
}
</pre>
<p>As you can see in the above code, I&#8217;ve placed the two images in a division and given them absolute positioning to assign their positions in the division. </p>
<p>To achieve the Horizontal flip we are basically reducing the width of the first image to 0 pixels, increasing the left side margin from zero to half it&#8217;s width and as soon as we finish that, Increase the width of the second image from zero to it&#8217;s actual width and do the opposite for left side margin what we did for the first image i.e reduce it from half the width of the image to zero.</p>
<p>This process takes place when you click on the first image (#image1) and the same process also takes place when you click on second image (#image2) except for the obvious shuffle in their ids.</p>
<p>Just look at the jQuery code below and you will have a better idea of what&#8217;s happening:</p>
<h3>jQuery:</h3>
<pre class="code">
$(document).ready(function(){
var margin =$("#image1").width()/2;
var width=$("#image1").width();
var height=$("#image1").height();

$("#image2").stop().css({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'});
$("#reflection2").stop().css({width:'0px',height:''+height+'px',marginLeft:''+margin+'px'});

	$("#image1").click(function(){
		$(this).stop().animate({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'},{duration:500});
		window.setTimeout(function() {
		$("#image2").stop().animate({width:''+width+'px',height:''+height+'px',marginLeft:'0px',opacity:'1'},{duration:500});
		},500);
	});

	$("#image2").click(function(){
		$(this).stop().animate({width:'0px',height:''+height+'px',marginLeft:''+margin+'px',opacity:'0.5'},{duration:500});
		window.setTimeout(function() {
		$("#image1").stop().animate({width:''+width+'px',height:''+height+'px',marginLeft:'0px',opacity:'1'},{duration:500});
		},500);
	});

});
</pre>
<p><strong>If you want to perform a Vertical flip the jQuery code for that too is included in the source code.</strong></p>
<p>Feel free to leave comments if you appreciate the tutorial or if you have any queries. You can also criticize the work but don&#8217;t be rude.</p>
<p>You can always find some good tutorials and articles on the <a href="http://webmuch.com/resources/" alt="Resources Page">Resources</a> page. You can always reach it using the menu up-top.</p>
<p>Thanks for Reading!</p>
<p><strong><a href="http://webmuch.com/source_files/image_flip_source.zip">Download the Source Code</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://webmuch.com/image-flip-using-jquery/feed/</wfw:commentRss>
		<slash:comments>52</slash:comments>
		</item>
		<item>
		<title>Animated Navigation Bar Using jQuery</title>
		<link>http://webmuch.com/animated-navigation-bar-using-jquery/</link>
		<comments>http://webmuch.com/animated-navigation-bar-using-jquery/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 00:07:58 +0000</pubDate>
		<dc:creator>Aayush</dc:creator>
				<category><![CDATA[JavaScript & AJAX]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://webmuch.com/?p=150</guid>
		<description><![CDATA[<img src="http://webmuch.com/wp-content/uploads/2009/06/intro.png" alt="Animated Navigation Bar Using jQuery Introduction Image" title="Animated Navigation Bar Using jQuery Introduction Image" width="150" height="150" class="alignnone size-full wp-image-161" />For my first Article I will be writing on creating an Animated Navigation Bar Using jQuery. Hopefully you guys will like it.]]></description>
			<content:encoded><![CDATA[<p>This is my first guest tutorial at WebMuch so please bear with me if I miss out on anything.</p>
<h3>Preview:</h3>
<p><img class="alignnone size-full wp-image-155" title="Animated Navigation Bar Using jQuery Preview" src="http://webmuch.com/wp-content/uploads/2009/06/preview.png" alt="Animated Navigation Bar Using jQuery Preview" width="585" height="47" /></p>
<h3><a href="http://webmuch.com/demos/jQ_animated_navbar/navbar.html">DEMO!</a></h3>
<p>I am assuming that the readers are well versed with CSS and HTML.</p>
<h3>HTML Code:</h3>
<pre class="code">&lt;div class="container"&gt;
    &lt;div id="navbar1"&gt;
       	&lt;ul id="sprite"&gt;
       		&lt;li id="b0" class="a0"&gt;Home&lt;/li&gt;
                &lt;li id="b1"&gt;News&lt;/li&gt;
                &lt;li id="b2"&gt;Blog&lt;/li&gt;
                &lt;li id="b3"&gt;Pictures&lt;/li&gt;
                &lt;li id="b4"&gt;Videos&lt;/li&gt;
                &lt;li id="b5"&gt;Gallery&lt;/li&gt;
                &lt;li id="b6"&gt;About&lt;/li&gt;
                &lt;li id="b7" style="border-right:1px solid #1f1f1f;"&gt;Contact&lt;/li&gt;
        	&lt;/ul&gt;
        &lt;/div&gt;
&lt;/div&gt;</pre>
<p><strong>*NOTE:</strong> I do not encourage inline styling, I did it because It&#8217;s a sin I was willing to commit.</p>
<h3>CSS Code:</h3>
<pre class="code">html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, code,
del, dfn, em, img, q, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
	margin: 0;
	padding: 0;
	border: 0;
	font-weight: inherit;
	font-style: inherit;
	font-size: 100%;
	font-family: inherit;
	vertical-align: baseline;
}
body{
background-color:#1f1f1f;
}
.container{
	width:960px;
	margin:0px auto;
	color:#FFFFFF;
	font-family:Arial,sans-serif;
	font-size:20px;
	font-weight:bold;
}
#navbar1{
	float:left;
	width:960px;
	height:36px;
	font-size:14px;
	margin:20px 0 0 0;
	background:url(images/navbar_bg.png);
}
#navbar1 ul{
	float:left;
	width:585px;
	height:36px;
	margin-left:188px;
	color:#000000;
}
#navbar1 ul{
	background: url(images/anim_3.png) no-repeat;
	background-position:1px 4px;
}
#navbar1 ul li{
	float:left;
	width:72px;
	margin:3px 0 0 0;
	height:22px;
	display: inline;
	text-align:center;
	padding:7px 0 0 0;
	border-left:1px solid #1f1f1f;
	cursor:pointer;
}</pre>
<p><strong>*NOTE: </strong>This tutorial is only effective when using a predefined width for each button or list item as shown in the above image, this can also be implemented on navigation bars using dynamic widths, but you might have to change the jQuery and the image sprite quite a bit to achieve any kind of consistency in your design. Well to give you a basic explanation as to how we will animate the navigation bar from here on in, we will take a background image equal to the size of the list item, which, on mouse-over positions itself to the left of each respective list item. So, as you can see in my HTML code I have named(id) my unordered list as &#8216;sprite&#8217; with a backround image. I have also named(id) my list items b0,b1,b2,b3&#8230;.b7, depending on the number of list items you wish to have in your navigation bar. I&#8217;ll explain why we are doing this in a bit, after you read through the jQuery code.</p>
<h3>jQuery Code:</h3>
<pre class="code">$(document).ready(function(){
	var selected=0; // Default background position
	var position=0;

	$("#sprite").css({backgroundPosition:''+selected+'px 4px'});

	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).mouseover(function(){
	position=$(this).attr("id").slice(1,2)*($(this).outerWidth());
	/*width of your list item*/
	$("#sprite").stop().animate({backgroundPosition:''+position+'px 4px'},{duration:200});
	});

	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).mouseout(function(){
	$("#sprite").stop().animate({backgroundPosition:''+selected+'px 4px'},{duration:200});
	});
});</pre>
<h3>Step By Step Read Through:</h3>
<ul>
<li>In the first line, we define the default background position of the background image of #sprite (even though, we&#8217;ve already mentioned the default background position in the CSS file, we still have to declare the default background position in jQuery, because for some reason, Internet Explorer shows an error after repeated mouse-over states).</li>
<li>Now, on mouse-over of any of the list items, we simply calculate the background position of the image in the background of #sprite and using the animate method of jQuery we move it to its destined location. For example: On mouse-over of b0, in my case I moved it 0 * 73(width of my button) i.e. 0 pixels from the left of #sprite. On mouse-over of b1, I moved it 1 * 73 i.e. 73 pixels from the left of #sprite. On mouse-over of b2, I moved it 2 * 73 i.e. 146 pixels from the left of #sprite, so on and so forth. That is the very reason I named (id) my list items b0, b1, b2…, so that I can slice out the numerical values from it using slice(1,2).</li>
<li>Using the sliced numerical values we calculate the position of the background image, finally animate it and avoid a list of if else statements for each list item.</li>
<li>On mouse-out of any of the list items the background image comes back to its original position i.e. 0px (var selected;) from the left and 4px from the top.</li>
<li>Now, if you got any of the stuff I&#8217;ve explained there is one question popping in your head that do I have to manually give value to the variable &#8220;selected&#8221; for every page , well to avoid this you just have to edit the jQuery from the top to the one below.</li>
</ul>
<pre class="code">&lt;script type="text/javascript"&gt;
$(document).ready(function(){
	var check;
	var i;
	for(i=0;i&lt;20;i++){
		if($(".a"+i+"").attr("id")){
		check=$(".a"+i+"").attr("id").slice(1,2);
		}
	}

	var selected=check*($("#b0").outerWidth());
	var position;

	$("#sprite").css({backgroundPosition:''+selected+'px 4px'});

	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).mouseover(function(){
	position=$(this).attr("id").slice(1,2)*($("#b0").outerWidth());/*width of your list item*/
	$("#sprite").stop().animate({backgroundPosition:''+position+'px 4px'},{duration:300});
	});

	$("#b0,#b1,#b2,#b3,#b4,#b5,#b6,#b7").css({backgroundPosition:'0px 0px'}).mouseout(function(){
	$("#sprite").stop().animate({backgroundPosition:''+selected+'px 4px'},{duration:300});
	});
});

&lt;/script&gt;</pre>
<p>Now we can easily name the class a0 or a1 or a2 or a4 of our list item (active list item) in our HTML to set the default background position of our background in #sprite and the script basically looks for the class with prefix &#8220;a&#8221; then slices out the next element i.e. 0 or 1 or 2 or 3, etc and multiplies it to the width of the element and gives it a default position from the left.</p>
<p>Feel free to leave comments if you appreciate the tutorial or if you have any problems implementing it.</p>
<p>Thanks for reading.</p>
<p><strong><a href="http://webmuch.com/source_files/Anim_navbar_webmuch.zip">Download the Source Code</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://webmuch.com/animated-navigation-bar-using-jquery/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>How &amp; why you should use Google CDN</title>
		<link>http://webmuch.com/how-why-you-should-use-google-cdn/</link>
		<comments>http://webmuch.com/how-why-you-should-use-google-cdn/#comments</comments>
		<pubDate>Sat, 30 May 2009 14:47:37 +0000</pubDate>
		<dc:creator>Aayush</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[JavaScript & AJAX]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://webmuch.com/?p=133</guid>
		<description><![CDATA[<img src="http://webmuch.com/wp-content/uploads/2009/05/intro2.jpg" alt="jQuery Google CDN Image" title="jQuery Google CDN Image" width="150" height="150" class="alignnone size-full wp-image-136" />In this article I will share the importance of using a Google CDN link of our favorite JavaScript library and how to implement it with two different methods.]]></description>
			<content:encoded><![CDATA[<h3>What is Google’s CDN?</h3>
<p>Google CDN stands for Google Content Distribution Network. It provides a loading architecture for the most popular, open source JavaScript libraries.</p>
<p><img class="alignnone size-full wp-image-134" title="Available JavaScript Libraries Image" src="http://webmuch.com/wp-content/uploads/2009/05/preview2.jpg" alt="Available JavaScript Libraries Image" width="585" height="548" /></p>
<h3>Why should I use Google’s CDN links?</h3>
<p>Most of the websites I see, still host their JavaScript Library on their own server (Most, not all). Actually never have I ever seen any Web Development Blog hosting the library on their own server. They always use Google CDN, which is great because it has a number of advantages:</p>
<ol>
<li>Google’s Content Distribution Network has libraries on their various servers across the world and if you use their CDN link, when a user’s browser resolves the URL, their browser will automatically download the file from the closest available server, which will be a much faster download than if you force a user to download the file from your host server in whichever country your website is hosted.</li>
<li>Google’s Content Distribution Network will save you a great deal of bandwidth if you have large traffic on your website and a limited bandwidth with your host.</li>
<li>There is a good chance that the Google hosted version of that library is already cached on the user’s browser cache, as lot of big websites and portals use Google’s CDN links including Google itself and Google’s servers instruct browsers to cache the file for one year if there are quite a few requests for the same hosted file.</li>
</ol>
<h3>How to use Google CDN?</h3>
<p>Google’s CDN provides most of the popular, open source JavaScript Libraries with two ways of using each of them via the direct path in the &lt;script/&gt; tags and via The Google AJAX Libraries API.</p>
<p>To use the Google AJAX Libraries API we need to include the Google &#8220;jsapi&#8221; script:</p>
<pre class="code">&lt;script src="http://www.google.com/jsapi"&gt;&lt;/script&gt;</pre>
<p>The Google AJAX Libraries API provides a simple and powerful google.load() method which accepts two arguments, the first argument to google.load is the name of a library. The second argument is the version of the library:</p>
<pre class="code">&lt;script&gt;
google.load("jquery", "1.3.2");
google.load("jqueryui", "1.7.1");
    google.setOnLoadCallback(function(){
        // use this instead of:
        /*
            $(document).ready(function(){  });
        */
    });
&lt;/script&gt;</pre>
<p>But to use this API, there is a different approach for the ready functions of all the libraries. For example, in the above code, we use google.setOnLoadCallback(function(){  });  instead of jQuery’s ready function. In-fact we use google.setOnLoadCallback(function(){  });  instead of all different library’s ready functions. This can be seen as a drawback or a good feature; I see it as a good feature as it gives me a single ready function for all libraries.</p>
<p>The second method to use Google’s CDN links is by the direct paths of the libraries in the &lt;script/&gt; tags</p>
<p>Below is a list of all the JavaScript Libraries Google CDN provides with the direct paths and google.load implementation:</p>
<h3>jQuery</h3>
<pre class="code">
name: jquery
versions: 1.2.3, 1.2.6, 1.3.0, 1.3.1, 1.3.2
load request: google.load("jquery", "1.3.2");
extras: uncompressed:true, e.g., google.load("jquery", "1.3.2", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
path(u): http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
</pre>
<h3>jQuery UI</h3>
<pre class="code">
name: jqueryui
versions: 1.5.2, 1.5.3, 1.6, 1.7.0, 1.7.1
load request: google.load("jqueryui", "1.7.1");
extras: uncompressed:true, e.g., google.load("jqueryui", "1.7.1", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js
path(u): http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.js
note: This library depends on jquery. Before loading this module, you must load jquery. e.g.:
        google.load("jquery", "1.3.2");
        google.load("jqueryui", "1.7.1");
</pre>
<h3>Prototype</h3>
<pre class="code">
name: prototype
versions: 1.6.0.2, 1.6.0.3
load request: google.load("prototype", "1.6.0.3");
path: http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js
</pre>
<h3>script.aculo.us</h3>
<pre class="code">
name: scriptaculous
versions: 1.8.1, 1.8.2
load request: google.load("scriptaculous", "1.8.2");
path: http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/scriptaculous.js
note: This library depends on Prototype. Before loading this module, you must load Prototype. e.g.:
        google.load("prototype", "1.6");
        google.load("scriptaculous", "1.8.2");
</pre>
<h3>MooTools</h3>
<pre class="code">
name: mootools
versions: 1.11, 1.2.1, 1.2.2
load request: google.load("mootools", "1.2.2");
extras: uncompressed:true, e.g., google.load("mootools", "1.2.2", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools-yui-compressed.js
path(u): http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools.js
</pre>
<h3>Dojo</h3>
<pre class="code">
name: dojo
versions: 1.1.1, 1.2.0, 1.2.3, 1.3.0, 1.3.1
load request: google.load("dojo", "1.3.1");
extras: uncompressed:true, e.g., google.load("dojo", "1.3.1", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/dojo/1.3.1/dojo/dojo.xd.js
path(u): http://ajax.googleapis.com/ajax/libs/dojo/1.3.1/dojo/dojo.xd.js.uncompressed.js
</pre>
<h3>SWFObject</h3>
<pre class="code">
name: swfobject
versions: 2.1
load request: google.load("swfobject", "2.1");
extras: uncompressed:true, e.g., google.load("swfobject", "2.1", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js
path(u): http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject_src.js
</pre>
<h3>Yahoo! User Interface Library (YUI)</h3>
<pre class="code">
name: yui
versions: 2.6.0, 2.7.0
load request: load request: google.load("yui", "2.7.0");
extras: uncompressed:true, e.g., google.load("yui", "2.7.0", {uncompressed:true});
path: http://ajax.googleapis.com/ajax/libs/yui/2.7.0/build/yuiloader/yuiloader-min.js
path(u): http://ajax.googleapis.com/ajax/libs/yui/2.7.0/build/yuiloader/yuiloader.js
</pre>
<p>Source: <a href="http://code.google.com/apis/ajaxlibs/documentation/#AjaxLibraries">Google</a></p>
<p>Thanks for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://webmuch.com/how-why-you-should-use-google-cdn/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
