<?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>Last Webdesigner a blog about Web Design &#187; menu</title>
	<atom:link href="http://lastwebdesigner.com/tag/menu/feed" rel="self" type="application/rss+xml" />
	<link>http://lastwebdesigner.com</link>
	<description>Resources for web designers</description>
	<lastBuildDate>Wed, 19 Aug 2009 10:19:11 +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>Simple animated menu with jquery</title>
		<link>http://lastwebdesigner.com/jquery/simple-animated-menu-with-jquery.html</link>
		<comments>http://lastwebdesigner.com/jquery/simple-animated-menu-with-jquery.html#comments</comments>
		<pubDate>Wed, 10 Jun 2009 13:50:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Jquery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://lastwebdesigner.com/?p=173</guid>
		<description><![CDATA[Jquery is, of course, one the best( or the best) JavaScript framework actually. With jquery we can create amazing effects on the web pages, writing some few lines of codes, and you don&#8217;t need to be an experienced web programmer. In this post I will show you how to create a nice and simple vertical [...]


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p><a title="jquery" href="http://docs.jquery.com/Downloading_jQuery"><strong>Jquery</strong></a> is, of course, one the best( or the best) JavaScript framework actually.</p>
<p>With <strong>jquery</strong> we can create amazing effects on the web pages, <span style="text-decoration: underline;">writing some few lines of codes, and you don&#8217;t need to be an experienced web programmer.<br />
</span></p>
<p>In this post I will show you how to create a nice and <strong>simple vertical menu with css and jquery</strong>, writing few lines of  code. <span id="more-173"></span></p>
<p>You can see the final result at <a title="animated menu with jquery" href="http://lastwebdesigner.freewebhostx.com/simple-jquery-menu/">this page</a>, and you can download the complete source code with example from here.<br />
First, <a title="jquery" href="http://docs.jquery.com/Downloading_jQuery">download <strong>jquery</strong> from the <strong>official site</strong>,</a> and after link it to your document. I&#8217;ve chooses to put the source code, for the css style and the javascript-jquery, in another file, you can put all in one if you want, IMHO I think is always better to separate it, it&#8217;s your choose.<br />
Create the page and links the javascript file it&#8217;s really easy, how I suppose you know :</p>
<blockquote><p><strong>&lt;link href=&#8221;style.css&#8221; rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221;/&gt;<br />
&lt;script src=&#8221;js/jquery.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;<br />
&lt;script src=&#8221;js/menu.js&#8221; type=&#8221;text/javascript&#8221;&gt;&lt;/script&gt;</strong></p></blockquote>
<p>After I&#8217;ve created a simple page structure, with the menu,like the &#8220;semantic&#8221; want,  is  in a  list, in this case unordered :</p>
<blockquote><p><strong>&lt;div id=&#8221;navigation&#8221;&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Home&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Freebies&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Tutorials&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Downloads&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#&#8221;&gt;Contact&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;/div&gt;</strong></p></blockquote>
<h3>Now  style the menu :</h3>
<blockquote><p><strong>#navigation{<br />
width: 200px;<br />
}<br />
#navigation ul{<br />
list-style: none;<br />
}<br />
#navigation ul li{<br />
height: 30px;<br />
border-bottom: 1px dotted #ccc;<br />
}<br />
#navigation ul li a{<br />
text-indent: 20px;<br />
padding: 5px 0;<br />
display: block;<br />
height: 20px;<br />
text-decoration: none;<br />
color: #434343;<br />
background-image: url(bull.png);<br />
background-repeat: no-repeat;<br />
background-position: 5px 6px ;<br />
}<br />
#navigation ul li a:hover{<br />
background-color: #8E8963;<br />
background-image: url(bull.png);<br />
background-repeat: no-repeat;<br />
background-position: 15px 6px ;<br />
color: white;<br />
}</strong></p></blockquote>
<p>What I&#8217;ve done here? Simply :</p>
<p>give to a menu a fixed with, styling the<strong> li </strong>and the <strong>link </strong> , give to a link a <span style="text-decoration: underline;">background image</span> <strong>(background-image: url(bull.png)</strong>; ) and when the mouse is over  (<span style="text-decoration: underline;"><strong>a:hover</strong></span>) , change the background color (not the image) and the <strong>link color.</strong></p>
<p>Another thing to note is that I&#8217;ve used the <strong>backround-position property </strong>for the image, so with this I can move the image around  changing the values of the position (X and Y axis) and make this appear aligned with the text.</p>
<p>With <strong>Jquery</strong> I will &#8220;<strong>move</strong>&#8221; and <span style="text-decoration: underline;">animate</span> the<span style="text-decoration: underline;"> link on the right</span> when the <strong>mouse is over,</strong> so I need to move the image too, and for the reason that I&#8217;ve used the image like background and no like image in the html code, I need to move that when the link will animated, maybe using directly the image in the code the effect will come better, you can try at your own.</p>
<p>Ok now we can go to our <strong>javascript</strong> and write the <strong>jquery</strong>-code . Create a new js file and call &#8220;<strong>menu.js&#8221;</strong>, write this simple code :</p>
<blockquote><p><strong>$(document).ready(function(){<br />
var Duration = 150; //time in milliseconds</strong></p>
<p><strong>$(&#8216;#navigation ul li a&#8217;).hover(function() {<br />
$(this).animate({ paddingLeft: &#8217;20px&#8217; }, Duration);<br />
}, function() {<br />
$(this).animate({ paddingLeft: &#8217;0px&#8217; }, Duration);<br />
});</strong></p>
<p><strong>});</strong></p></blockquote>
<p>OK  let me explain this code:</p>
<p>The first thing is to tell to <strong>jquery</strong> that, when the <strong>DOM</strong> <span style="text-decoration: underline;">is loaded</span> ( this is rally important)  :</p>
<blockquote><p><strong>$(document).ready(function(){<br />
});</strong></p></blockquote>
<p>This is the first thing that you <span style="text-decoration: underline;">must learn</span> about <strong>Jquery</strong>, with this piece of code, you will tell to <strong>Jquery</strong> this :  &#8220;do the instruction only when the entire document is loaded&#8221;.</p>
<p>This is great and really usefull because  you don&#8217;t have to put any &#8220;behavioral&#8221; markup in the HTML, and this is the reason why you can separate every <strong>Javascript</strong> from the document.</p>
<p>After I&#8217;ve created the function that must be executed when the DOM is ready :</p>
<blockquote><p><strong>var Duration = 150; //time in milliseconds</strong></p>
<p><strong>$(&#8216;#navigation ul li a&#8217;).hover(function() {<br />
$(this).animate({ paddingLeft: &#8217;20px&#8217; }, Duration);<br />
}, function() {<br />
$(this).animate({ paddingLeft: &#8217;0px&#8217; }, Duration);<br />
});</strong></p></blockquote>
<p>And it&#8217;s all! What it means this? I will try to explain in a simple words :</p>
<p>With the <strong>$()</strong>, you can get every element of the <strong>DOM</strong>, an it is like the <strong>documentGetElement</strong> in the normal javascript.</p>
<p>So I Want that ,when the mouse is over the tag li inside the navigation div, start the animation effect, so I&#8217;ll &#8220;take&#8221; this element with the dollar function</p>
<blockquote><p><strong>$(&#8216;#navigation ul li a&#8217;)</strong></p></blockquote>
<p><span style="text-decoration: underline;">This is the second important thing you must learn on Jquery. <img src='http://lastwebdesigner.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' title="Simple animated menu with jquery" /> </span></p>
<p>And finally, I&#8217;ve used the animation on the menu, using the <strong>animate function </strong>of <strong>jquery</strong>, really simple to use, in this case I gave<span style="text-decoration: underline;"><strong> 20px at padding-left css property</strong></span> to make that the text &#8220;move&#8221; on the right side .</p>
<blockquote><p><strong>$(this).animate({ paddingLeft: &#8217;20px&#8217; }, Duration);</strong></p></blockquote>
<p>The<strong> $(this)</strong> refer to the element that we are using, animate is the <strong>jquery</strong> function (following the link you can learn more about this function) and <strong>Duration</strong> is the duration of the time, I&#8217;ve used a starting variable to give a value <strong>(var Duration = 150; ).</strong></p>
<p>The rest of the code is another function to  ensure that the link returns at the original position.</p>
<blockquote><p><strong>,function() {<br />
$(this).animate({ paddingLeft: &#8217;0px&#8217; }, Duration);<br />
});</strong></p></blockquote>
<p>Conclusion : <strong>Jquery</strong> is the best<span style="text-decoration: underline;"> framework that I&#8217;ve ever used</span>, is simple, easy to learn and make the web designer&#8217;s life really easy, although you are not a experienced programmer.</p>
<p>Here the link relativies to <strong>jquery</strong> and maybe utils for this simple tutorial :</p>
<p><a title="jquery" href="http://docs.jquery.com/Downloading_jQuery"><strong>Download Jquery</strong></a></p>
<p><a title="learn jquery" href="http://www.learningjquery.com/"><strong>Learn Jquery</strong></a></p>
<p><strong><a title="animate function" href="http://docs.jquery.com/Effects/animate#paramsdurationeasingcallback">The animate function of jquery</a><br />
</strong></p>
<h4>Well you can see the final results here :</h4>
<blockquote><p><a title="simple jquery menu" href="http://lastwebdesigner.freewebhostx.com/simple-jquery-menu/"><strong>Simple menu with Jquery.</strong></a></p></blockquote>
<p><a class="download" title="jquery simple menu" href="http://lastwebdesigner.com/downloads/jquery-simple-menu.zip">Download jquery simple menu with example :</a><br />
<h3 class="related-title">This posts may be interesting too</h3>
<ul class="related_post">
<li><a href="http://lastwebdesigner.com/jquery/how-to-send-a-mail-with-php-ajax-and-jquery-in-facebook-style.html" title="How to send a mail with php ajax and jquery in facebook style">How to send a mail with php ajax and jquery in facebook style</a></li>
<li><a href="http://lastwebdesigner.com/photoshop/create-a-badge-20-with-photoshop.html" title="Create a badge 2.0 with Photoshop">Create a badge 2.0 with Photoshop</a></li>
<li><a href="http://lastwebdesigner.com/photoshop/create-a-fire-text-with-photoshop.html" title="Create a fire text with Photoshop">Create a fire text with Photoshop</a></li>
<li><a href="http://lastwebdesigner.com/web-design/last-mac-editors-collection.html" title="Last Mac editors collection.">Last Mac editors collection.</a></li>
<li><a href="http://lastwebdesigner.com/photoshop/rain-effect-with-photoshop-in-6-steps.html" title="Rain effect with photoshop in 6 steps">Rain effect with photoshop in 6 steps</a></li>
</ul>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://lastwebdesigner.com/jquery/simple-animated-menu-with-jquery.html/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
