<?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>Wai Yan Lin &#187; jQuery</title>
	<atom:link href="http://blog.waiyanlin.net/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.waiyanlin.net</link>
	<description></description>
	<lastBuildDate>Wed, 11 Aug 2010 02:30:07 +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>Tutorial: How to create a simple drop-down menu jQuery plugin</title>
		<link>http://blog.waiyanlin.net/2010/08/11/tutorial-how-to-create-a-simple-drop-down-menu-jquery-plugin/</link>
		<comments>http://blog.waiyanlin.net/2010/08/11/tutorial-how-to-create-a-simple-drop-down-menu-jquery-plugin/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 02:30:07 +0000</pubDate>
		<dc:creator>waiyan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.waiyanlin.net/?p=207</guid>
		<description><![CDATA[I&#8217;ve been using jQuery for quite a long time and simply love the power of it. It helps to speed up my development time like what they say: &#8216;write less, do more&#8217;. And I also used many jQuery plugins depending on my development&#8217;s needs. There are many great plugins which...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using jQuery for quite a long time and simply love the power of it. It helps to speed up my development time like what they say: &#8216;write less, do more&#8217;. And I also used many jQuery plugins depending on my development&#8217;s needs. There are many great plugins which will make your life much easier.</p>
<p>In this tutorial, I will share how to write a simple plugin for your drop-down navigation menu.</p>
<p><strong>Basic Structure</strong></p>
<p>Lets take a look at the basic structure of jQuery plugin. (If you wish, you can read <a href="http://docs.jquery.com/Plugins/Authoring" target="_blank">the official article</a> for writing a plugin)</p>
<blockquote><p>(function($) {</p>
<p>$.fn.yourplugin = function() {</p>
<p>this.each(function() {    <span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span> //your code comes here</p>
<p>});</p>
<p>return this;</p>
<p>};</p>
<p>})(jQuery);</p>
</blockquote>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">(function($) {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">$.fn.yourplugin = function() {</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">this.each(function() {    <span style="white-space: pre;"> </span></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span style="white-space: pre;"> </span> //your code comes here</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">});</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">return this;</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">};</div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 16px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">})(jQuery);</div>
<p><strong>Options</strong></p>
<p><strong><span style="font-weight: normal; ">You might want to include some options to let the users to change easily without touching your plugin&#8217;s code. </span></strong></p>
<blockquote><p>(function($) {</p>
<p>$.fn.yourplugin = function() {</p>
<p>//set default values of your options</p>
<p>var config = {</p>
<p><span style="white-space:pre"> </span> &#8216;option1&#8242;: value&#8217;,</p>
<p><span style="white-space:pre"> </span> &#8216;option2&#8242;: &#8216;value&#8217;</p>
<p>};</p>
<p>var settings = $.extend(config, settings);</p>
<p>this.each(function() {</p>
<p><span style="white-space:pre"> </span> //default options. you can call your settings like &#8216;s.option1&#8242; or &#8216;s.option2&#8242;<span style="white-space:pre"> </span> <span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span> var s = settings;</p>
<p>//your code comes here</p>
<p>});</p>
<p>return this;</p>
<p>};</p>
<p>})(jQuery);</p>
</blockquote>
<p>Now we know what basic plugin structure looks like. Lets create our very simple drop-down menu plugin. First of all, we need to create a navigation menu before we move on to the plugin. Here&#8217;s how it looks like:</p>
<blockquote><p>&lt;div id=&#8221;navwrap&#8221;&gt;</p>
<p>&lt;ul id=&#8221;nav&#8221;&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1&lt;/a&gt;</p>
<p>&lt;ul&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1.1&lt;/a&gt;</p>
<p>&lt;ul&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1.1.1&lt;/a&gt;</p>
<p>&lt;ul&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1.1.1.1&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;/ul&gt;</p>
<p>&lt;/li&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1.1.2&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;/ul&gt;</p>
<p>&lt;/li&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1.2&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 1.3&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;/ul&gt;</p>
<p>&lt;/li&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 2 Is Long&lt;/a&gt;</p>
<p>&lt;ul&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 2.1&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;/ul&gt;</p>
<p>&lt;/li&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 3&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Menu Item 4&lt;/a&gt;&lt;/li&gt;</p>
<p>&lt;/ul&gt;</p>
<p>&lt;/div&gt;</p>
</blockquote>
<p><strong>CSS</strong></p>
<p>Then, we need to set some css rules for our menu.</p>
<blockquote><p>ul#nav{</p>
<p><span style="white-space:pre"> </span>list-style: none;</p>
<p><span style="white-space:pre"> </span>margin: 0;</p>
<p><span style="white-space:pre"> </span>padding: 0;</p>
<p><span style="white-space:pre"> </span>position: relative;</p>
<p>}</p>
<p>ul#nav li{</p>
<p><span style="white-space:pre"> </span>float:left;</p>
<p><span style="white-space:pre"> </span>background-color: #0088AA;</p>
<p><span style="white-space:pre"> </span>position:relative;</p>
<p><span style="white-space:pre"> </span>display:block;</p>
<p><span style="white-space:pre"> </span>margin-right:1px;</p>
<p><span style="white-space:pre"> </span>font-size:14px;</p>
<p>}</p>
<p>ul#nav li a{</p>
<p><span style="white-space:pre"> </span>color:#FFF;</p>
<p><span style="white-space:pre"> </span>text-decoration: none;<span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span>padding:5px;</p>
<p><span style="white-space:pre"> </span>display:block;</p>
<p><span style="white-space:pre"> </span>position:relative;</p>
<p><span style="white-space:pre"> </span>width:100%;</p>
<p>}</p>
<p>ul#nav ul{</p>
<p><span style="white-space:pre"> </span>margin:0;</p>
<p><span style="white-space:pre"> </span>padding:0;</p>
<p><span style="white-space:pre"> </span>position:absolute;</p>
<p><span style="white-space:pre"> </span>width:100%;</p>
<p>}</p>
<p>ul#nav li li{</p>
<p><span style="white-space:pre"> </span>position:relative;</p>
<p><span style="white-space:pre"> </span>background-color:#0077AA;</p>
<p><span style="white-space:pre"> </span>display:block;</p>
<p><span style="white-space:pre"> </span>margin:0;</p>
<p><span style="white-space:pre"> </span>border-top:solid 1px #FFF;</p>
<p><span style="white-space:pre"> </span>width:100%;</p>
<p><span style="white-space:pre"> </span>font-size:11px;</p>
<p>}</p>
<p>ul#nav ul ul{</p>
<p><span style="white-space:pre"> </span>position:absolute;</p>
<p><span style="white-space:pre"> </span>left:100%;</p>
<p><span style="white-space:pre"> </span>top:0;</p>
<p><span style="white-space:pre"> </span>margin:0 0 0 1px;</p>
<p><span style="white-space:pre"> </span>width:100%;</p>
<p>}</p>
</blockquote>
<p>Now, we will create the plugin which will use jQuery slideDown/Up effect for drop-down animation and giving one option for users to change the animation speed.</p>
<blockquote><p>(function($) {</p>
<p>$.fn.jDropDown = function(settings) {</p>
<p>//option for speed with default value of 500 milliseconds</p>
<p>var config = {</p>
<p><span style="white-space:pre"> </span> &#8216;speed&#8217;: &#8217;500&#8242;</p>
<p>};</p>
<p>var settings = $.extend(config, settings);</p>
<p>this.each(function() {</p>
<p><span style="white-space:pre"> </span> var s = settings;</p>
<p><span style="white-space:pre"> </span> var mainNav = this;    <span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span> //set css to all second ul to display none</p>
<p><span style="white-space:pre"> </span> $(mainNav).find(&#8216;ul&#8217;).css({&#8216;display&#8217;:'none&#8217;});    <span style="white-space:pre"> </span> <span style="white-space:pre"> </span> <span style="white-space:pre"> </span> <span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span> //hover event for each main li</p>
<p><span style="white-space:pre"> </span> $(mainNav).find(&#8216;li&#8217;).hover(</p>
<p><span style="white-space:pre"> </span>function(){</p>
<p><span style="white-space:pre"> </span>$(this).find(&#8216;ul:first&#8217;).slideDown(s.speed);    <span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span>},</p>
<p><span style="white-space:pre"> </span>function(){</p>
<p><span style="white-space:pre"> </span>$(this).find(&#8216;ul:first&#8217;).slideUp(s.speed);    <span style="white-space:pre"> </span></p>
<p><span style="white-space:pre"> </span>}</p>
<p><span style="white-space:pre"> </span>);</p>
<p><span style="white-space:pre"> </span></p>
<p>});</p>
<p>return this;</p>
<p>};</p>
<p>})(jQuery);</p>
</blockquote>
<p>This is all we have to do. Now, you can use this plugin by putting the following code in your html page between &lt;head&gt; and &lt;/head&gt;</p>
<blockquote><p>&lt;script&gt;</p>
<p>$(document).ready(function(){</p>
<p><span style="white-space:pre"> </span>$(&#8216;ul#nav&#8217;).jDropDown({</p>
<p><span style="white-space:pre"> </span>&#8216;speed&#8217;: 300</p>
<p><span style="white-space:pre"> </span>});</p>
<p>});</p>
<p>&lt;/script&gt;</p>
</blockquote>
<p>It is not too difficult to create your own jQuery plugin. I hope this tutorial will help you to write some cool plugins. If you have any doubt, feel free to write in the comment section below.</p>
<p><a href="http://blog.waiyanlin.net/example/jquery/jdropdown/" target="_blank">Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waiyanlin.net/2010/08/11/tutorial-how-to-create-a-simple-drop-down-menu-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Flying Text With Fade Effect</title>
		<link>http://blog.waiyanlin.net/2008/12/17/jquery-flying-text-with-fade-effect/</link>
		<comments>http://blog.waiyanlin.net/2008/12/17/jquery-flying-text-with-fade-effect/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 17:01:00 +0000</pubDate>
		<dc:creator>waiyan</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://blog.waiyanlin.net/?p=154</guid>
		<description><![CDATA[<p>With this great javascript framework, jQuery, you can create some flash like effects. In this post, I will show how to create very simple flying and fading text effect using jQuery. Here is live <a href="http://blog.waiyanlin.net/example/jquery/flyingtext.html" target="_blank">demo</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>With this great javascript framework, jQuery, you can create some flash like effects. In this post, I will show how to create very simple flying and fading text effect using jQuery. Here is live <a href="http://blog.waiyanlin.net/example/jquery/flyingtext.html" target="_blank">demo</a>.</p>
<p><code><span style="color: #000000;"></p>
<p></span></code></p>
<p><span style="color: #000000;">javascript:</span></p>
<blockquote><p>$(&#8216;.container .flying-text&#8217;).css({opacity:0}); //set all text opacity to 0</p>
<p>$(&#8216;.container .active-text&#8217;).animate({opacity:1, marginLeft: &#8220;350px&#8221;}, 4000); //animate first text</p>
<p>var int = setInterval(changeText, 5000); // call changeText function every 5 seconds</p>
<p>function changeText(){</p>
<p>var $activeText = $(&#8220;.container .active-text&#8221;); //get current text</p>
<p>var $nextText = $activeText.next();  //get next text</p>
<p>if($activeText.next().length == 0) $nextText = $(&#8216;.container .flying-text:first&#8217;); //if it is last text, loop back to first text</p>
<p>$activeText.animate({opacity:0}, 1000); //set opacity 0 to animated text</p>
<p>$activeText.animate({marginLeft: &#8220;-100px&#8221;}); //set animated text position to default</p>
<p>//animate next text</p>
<p>$nextText.css({opacity: 0}).addClass(&#8216;active-text&#8217;).animate({opacity:1, marginLeft: &#8220;350px&#8221;}, 4000, function(){</p>
<p>$activeText.removeClass(&#8216;active-text&#8217;);</p>
<p>});</p>
<p>}</p>
</blockquote>
<p>HTML:</p>
<blockquote><p>&lt;div class=&#8221;container&#8221;&gt;</p>
<p>&lt;h3 class=&#8221;flying-text active-text&#8221;&gt;I believe&lt;/h3&gt;</p>
<p>&lt;h3 class=&#8221;flying-text&#8221;&gt;I can&lt;/h3&gt;</p>
<p>&lt;h3 class=&#8221;flying-text&#8221;&gt;Fly&lt;/h3&gt;</p>
<p>&lt;/div&gt;</p>
</blockquote>
<p>CSS:</p>
<blockquote><p>body{</p>
<p>background-color:#000;</p>
<p>}</p>
<p>.container{</p>
<p>background-color:#000;</p>
<p>width:500px;</p>
<p>margin:0 auto;</p>
<p>color:#FFF;</p>
<p>overflow:hidden;</p>
<p>}</p>
<p>.flying-text{</p>
<p>margin-left:-100px;</p>
<p>}</p>
</blockquote>
<p>Check this live <a href="http://blog.waiyanlin.net/example/jquery/flyingtext.html" target="_blank">demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.waiyanlin.net/2008/12/17/jquery-flying-text-with-fade-effect/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

