<?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>Web design blog &#187; Jquery</title>
	<atom:link href="http://lastwebdesigner.com/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://lastwebdesigner.com</link>
	<description>Antonio Fullone &#039;s personal blog about web design</description>
	<lastBuildDate>Sat, 12 Nov 2011 18:39:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to send a mail with php ajax and jquery in facebook style</title>
		<link>http://lastwebdesigner.com/featured/how-to-send-a-mail-with-php-ajax-and-jquery-in-facebook-style.html</link>
		<comments>http://lastwebdesigner.com/featured/how-to-send-a-mail-with-php-ajax-and-jquery-in-facebook-style.html#comments</comments>
		<pubDate>Tue, 16 Jun 2009 15:17:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[featured]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Jquery]]></category>
		<category><![CDATA[PhP]]></category>
		<category><![CDATA[web 2.0]]></category>

		<guid isPermaLink="false">http://lastwebdesigner.com/?p=197</guid>
		<description><![CDATA[One of the website that I love is facebook. I&#8217;m not talking about the social network, well I like this social network, but I prefer twitter and linkedin for &#8220;professional use&#8221;, but this is another question, because I&#8217;m talking about the design.:) The use of web 2.0 effects and Ajax make this web site on [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flastwebdesigner.com%2Ffeatured%2Fhow-to-send-a-mail-with-php-ajax-and-jquery-in-facebook-style.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flastwebdesigner.com%2Ffeatured%2Fhow-to-send-a-mail-with-php-ajax-and-jquery-in-facebook-style.html&amp;style=normal&amp;service=bit.ly&amp;hashtags=ajax,javascript,Jquery,PhP,web+2.0&amp;b=2" height="61" width="50" title="How to send a mail with php ajax and jquery in facebook style" alt=" How to send a mail with php ajax and jquery in facebook style" /><br />
			</a>
		</div>
<p>One of the website that I love is <strong>facebook</strong>. I&#8217;m not talking about the <strong>social network, well I like this social network, but I prefer twitter and linkedin for &#8220;professional use&#8221;, but this is another question, because I&#8217;m talking about</strong> the design.:)</p>
<p>The use of <strong>web 2.0 effects</strong> and <strong>Ajax</strong> make this web site on of my favourites.</p>
<p>With this tutorial I will explain you<span style="text-decoration: underline;"><strong> how to create a message mail system like Facebook. <span id="more-197"></span><br />
</strong></span></p>
<p><span style="text-decoration: underline;"><strong> </strong></span>For make this we need to create some files.</p>
<h4>1. The index file with the mail form.</h4>
<h4>2.The mail.php file that process the form and send the mail, using the simple function mail() of php.</h4>
<h4>3.A css file .</h4>
<h4>4.Jquery, naturally.</h4>
<h4>5.An other Javascript, called Ajax.js, to interact with ajax, php and jquery.</h4>
<p>Surely you can put all in one file, but, for a better understanding and to have a clean code, I prefer to use different files for each one.</p>
<p>Well first of all <a title="send a mail with php jquery and ajax" href="http://lastwebdesigner.com/tests/mail-jquery-php-ajax/">you can see a demo of this page here, </a>for logical reason<span style="text-decoration: underline;"><strong> I&#8217;ve deleted my mail from the source code</strong></span>, / you can use your mail to test the script) this is the only thing that you need to change before use the source code, the rest is ready for use.</p>
<p> <img src='http://lastwebdesigner.com/wp-includes/images/smilies/icon_smile.gif' alt="icon smile How to send a mail with php ajax and jquery in facebook style" class='wp-smiley' title="How to send a mail with php ajax and jquery in facebook style" /> </p>
<p>OK, start with this tutorial.  First we need to create the form page and link to this page the <strong>jquery</strong> and <strong>ajax,js script, </strong>so this is the code :</p>
<blockquote><p><strong>&lt;div&gt;<br />
&lt;div id=&#8221;response&#8221;&gt;</strong></p>
<p><strong>&lt;/div&gt;<br />
&lt;form id=&#8221;formail&#8221; action=&#8221;" method =&#8221;post&#8221;&gt;<br />
&lt;label&gt;Name : &lt;/label&gt;<br />
&lt;input type=&#8221;text&#8221; name=&#8221;name&#8221; id=&#8221;name&#8221; /&gt;<br />
&lt;label&gt;Your mail :&lt;/label&gt;<br />
&lt;input type=&#8221;text&#8221; name=&#8221;mail&#8221; id=&#8221;mail&#8221; /&gt;<br />
&lt;label&gt;Subject : &lt;/label&gt;<br />
&lt;input type=&#8221;text&#8221; name=&#8221;subject&#8221; id=&#8221;subject&#8221; /&gt;<br />
&lt;label&gt;Text :&lt;/label&gt;<br />
&lt;textarea name=&#8221;text&#8221; id=&#8221;text&#8221; cols=&#8221;40&#8243; rows=&#8221;10&#8243;&gt;&lt;/textarea&gt;<br />
&lt;input type=&#8221;submit&#8221; value=&#8221;send mail&#8221; id=&#8221;sendmail&#8221; name=&#8221;sendmail&#8221; /&gt;<br />
&lt;/form&gt;<br />
&lt;/div&gt;</strong></p>
<p><strong>&lt;/div&gt;</strong></p></blockquote>
<p>The <strong>div</strong> called <strong>response</strong>, will be util for the validation and the text message after send the mail( or to get the error if the mail script doesn&#8217;t work), this <strong>div</strong> is really important don&#8217;t forget this.</p>
<p>Now we need to style this, you can style the form as you want, but the only important thing is that the<span style="text-decoration: underline;"> div response must be in display none</span> :</p>
<blockquote><p><strong>#response{display:none;}</strong></p></blockquote>
<p>Is better if you style this and the form, it will look more pretty this is the complete css that I&#8217;ve used :</p>
<blockquote><p><strong>body{<br />
background: #E7E7DC;<br />
font-size: 13px;<br />
font-family: arial;<br />
}<br />
#wrap{<br />
width: 800px;<br />
background: white;<br />
margin: auto;<br />
padding: 10px;<br />
}<br />
#wrap h1{<br />
padding: 10px;<br />
border: 1px solid #ccc;<br />
background: #f8f8f8;<br />
}<br />
.mail{<br />
width:500px;<br />
margin:auto;<br />
}<br />
#formail{<br />
width: 500px;<br />
margin: auto;<br />
}<br />
#formail label{<br />
display: block;<br />
margin: 10px 0;<br />
}<br />
#text{<br />
background: #f8f8f8;<br />
}<br />
#sendmail{<br />
margin-top: 20px;<br />
display: block;<br />
}<br />
#response{<br />
display: none;<br />
border: 1px solid #ccc;<br />
background: #FFFFA0;<br />
padding: 10px;<br />
width: 450px;<br />
}</strong></p></blockquote>
<p>This is the style of the page, now it comes the nice part, the php and the ajax, this will be funny! Let&#8217;s go and create the mail.php page, with this code :</p>
<blockquote><p><strong>&lt;?php<br />
$mail = $_POST['mail'];<br />
$name = $_POST['name'];<br />
$subject = $_POST['subject'];<br />
$text = $_POST['text'];</strong></p>
<p><strong>$to = &#8220;yourmail@domain.com&#8221;;<br />
$message =&#8221; You received  a mail from &#8220;.$mail;<br />
$message .=&#8221; Text of the message : &#8220;.$text;</strong></p>
<p><strong>if(mail($to, $subject,$message)){<br />
echo &#8220;mail successful send&#8221;;<br />
}<br />
else{<br />
echo &#8220;there&#8217;s some errors to send the mail, verify your server options&#8221;;<br />
}<br />
?&gt;</strong></p></blockquote>
<p>Ok, let me explain this:</p>
<p>Firs I create the variables that will contain the froms data values :</p>
<blockquote><p><strong>$mail = $_POST['mail'];<br />
$name = $_POST['name'];<br />
$subject = $_POST['subject'];<br />
$text = $_POST['text'];</strong></p></blockquote>
<p>With the variable<strong> $to</strong>, I store the mail where I want that the mail will be sended( my mail), <span style="text-decoration: underline;">this is the only thing that you must change to make works the script.</span></p>
<p>The <strong>$message</strong> variable get  the <strong>mail</strong> and the text of the <strong>sender</strong>, and put in the body of the mail message.</p>
<p>Finally , with tha <strong>mail() </strong>function from php I send the mail. I&#8217;ve used an if because, <strong>if the mail doesn&#8217;t work you will know. </strong></p>
<p>The mail function is really simple and accept some parameters, the mail where send, the subject and the message of the mail.</p>
<p><a title="mail function php" href="http://es2.php.net/manual/en/function.mail.php">You can read all from the official page of php. </a></p>
<blockquote><p>Now is the time of the<strong> ajax.js.</strong> This is the complete code :</p>
<p><strong>$(document).ready(function(){<br />
$(&#8220;#sendmail&#8221;).click(function(){<br />
var valid = &#8221;;<br />
var isr = &#8216; is required.&#8217;;<br />
var name = $(&#8220;#name&#8221;).val();<br />
var mail = $(&#8220;#mail&#8221;).val();<br />
var subject = $(&#8220;#subject&#8221;).val();<br />
var text = $(&#8220;#text&#8221;).val();<br />
if (name.length&lt;1) {<br />
valid += &#8216;&lt;br /&gt;Name&#8217;+isr;<br />
}<br />
if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {<br />
valid += &#8216;&lt;br /&gt;A valid Email&#8217;+isr;<br />
}<br />
if (subject.length&lt;1) {<br />
valid += &#8216;&lt;br /&gt;Subject&#8217;+isr;<br />
}<br />
if (text.length&lt;1) {<br />
valid += &#8216;&lt;br /&gt;Text&#8217;+isr;<br />
}<br />
if (valid!=&#8221;) {<br />
$(&#8220;#response&#8221;).fadeIn(&#8220;slow&#8221;);<br />
$(&#8220;#response&#8221;).html(&#8220;Error:&#8221;+valid);<br />
}<br />
else {<br />
var datastr =&#8217;name=&#8217; + name + &#8216;&amp;mail=&#8217; + mail + &#8216;&amp;subject=&#8217; + subject + &#8216;&amp;text=&#8217; + text;<br />
$(&#8220;#response&#8221;).css(&#8220;display&#8221;, &#8220;block&#8221;);<br />
$(&#8220;#response&#8221;).html(&#8220;Sending message &#8230;. &#8220;);<br />
$(&#8220;#response&#8221;).fadeIn(&#8220;slow&#8221;);<br />
setTimeout(&#8220;send(&#8216;&#8221;+datastr+&#8221;&#8216;)&#8221;,2000);<br />
}<br />
return false;<br />
});<br />
});<br />
function send(datastr){<br />
$.ajax({<br />
type: &#8220;POST&#8221;,<br />
url: &#8220;mail.php&#8221;,<br />
data: datastr,<br />
cache: false,<br />
success: function(html){<br />
$(&#8220;#response&#8221;).fadeIn(&#8220;slow&#8221;);<br />
$(&#8220;#response&#8221;).html(html);<br />
setTimeout(&#8216;$(&#8220;#response&#8221;).fadeOut(&#8220;slow&#8221;)&#8217;,2000);<br />
}<br />
});<br />
}</strong></p></blockquote>
<p>What i&#8217;ve done? let me explain :</p>
<p>I suppose that you know the<strong> $(document).ready function of jquery,</strong> I&#8217;ve explained in the previous tutorial, <a title="animated menu jquery" href="http://lastwebdesigner.com/jquery/simple-animated-menu-with-jquery.html">create an animated menu with jquery</a>.</p>
<p>When <strong>#sendmail,</strong> the submit button of the form,  is clicked will start <span style="text-decoration: underline;">the validation of the form,</span> this is important try always to validate your forms, expecially for the <strong>breakballs(usually called spammer&#8230;)</strong>, so the first part of the script validate the form and if on of the input value is under 0 this will stop the script and return an error like in this image</p>
<p><a href="http://lastwebdesigner.com/wp-content/uploads/2009/06/validation.jpg"><img class="alignnone size-full wp-image-198" title="validation" src="http://lastwebdesigner.com/wp-content/uploads/2009/06/validation.jpg" alt="validation How to send a mail with php ajax and jquery in facebook style" width="518" height="191" /></a></p>
<p>the text that appears is stored in the<strong> #response div</strong>, for this reason I said that is important and not only for this. <img src='http://lastwebdesigner.com/wp-includes/images/smilies/icon_smile.gif' alt="icon smile How to send a mail with php ajax and jquery in facebook style" class='wp-smiley' title="How to send a mail with php ajax and jquery in facebook style" /> </p>
<blockquote><p><strong>var valid = &#8221;;<br />
var isr = &#8216; is required.&#8217;;<br />
var name = $(&#8220;#name&#8221;).val();<br />
var mail = $(&#8220;#mail&#8221;).val();<br />
var subject = $(&#8220;#subject&#8221;).val();<br />
var text = $(&#8220;#text&#8221;).val();<br />
if (name.length&lt;1) {<br />
valid += &#8216;&lt;br /&gt;Name&#8217;+isr;<br />
}<br />
if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {<br />
valid += &#8216;&lt;br /&gt;A valid Email&#8217;+isr;<br />
}<br />
if (subject.length&lt;1) {<br />
valid += &#8216;&lt;br /&gt;Subject&#8217;+isr;<br />
}<br />
if (text.length&lt;1) {<br />
valid += &#8216;&lt;br /&gt;Text&#8217;+isr;<br />
}<br />
</strong></p></blockquote>
<p>To validate the mail, I&#8217;ve used a <strong>regular expression</strong>( <a title="Juan carlos Barreiro" href="http://enterprisedreams.net/">thanks to Juan Carlos</a> <img src='http://lastwebdesigner.com/wp-includes/images/smilies/icon_smile.gif' alt="icon smile How to send a mail with php ajax and jquery in facebook style" class='wp-smiley' title="How to send a mail with php ajax and jquery in facebook style" />  )</p>
<blockquote><p><strong>if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i))</strong></p></blockquote>
<p>if you try to write <strong>2 mail addres</strong>, this will not works, or if you use white space in the mail field the validation will stop the script. You can try simply leaving white the various fields to understand how it works. All of the error in the validation will appears in the <strong>response div</strong>, that will appear with a<strong> fadeIn effect.</strong></p>
<blockquote><p><strong>if (valid!=&#8221;) {<br />
$(&#8220;#response&#8221;).fadeIn(&#8220;slow&#8221;);<br />
$(&#8220;#response&#8221;).html(&#8220;Error:&#8221;+valid);<br />
}</strong></p></blockquote>
<p>The second part of the script is for create the <span style="text-decoration: underline;"><strong>datastr</strong></span> variable, that will store the value from the form and send in the <strong><span style="text-decoration: underline;">ajax request</span></strong>, and make appear again the <strong>#response div</strong>, yes how I said is important ejejeje, like the <strong>facebook</strong> style, that say that the message is sending.</p>
<blockquote><p><strong>else {<br />
var datastr =&#8217;name=&#8217; + name + &#8216;&amp;mail=&#8217; + mail + &#8216;&amp;subject=&#8217; + subject + &#8216;&amp;text=&#8217; + text;<br />
$(&#8220;#response&#8221;).css(&#8220;display&#8221;, &#8220;block&#8221;);<br />
$(&#8220;#response&#8221;).html(&#8220;Sending message &#8230;. &#8220;);<br />
$(&#8220;#response&#8221;).fadeIn(&#8220;slow&#8221;);<br />
setTimeout(&#8220;send(&#8216;&#8221;+datastr+&#8221;&#8216;)&#8221;,2000);<br />
}</strong></p></blockquote>
<p>In the final  part I&#8217;ve used a <strong>&#8220;return false</strong>&#8220;, so when you click on the submit button this doesn&#8217;t do nothing, well it seems that the button doesn&#8217;t do nothing, but the reason ts that the rest of the work is done by ajax and the function send :</p>
<blockquote><p><strong>function send(datastr){<br />
$.ajax({<br />
type: &#8220;POST&#8221;,<br />
url: &#8220;mail.php&#8221;,<br />
data: datastr,<br />
cache: false,<br />
success: function(html){<br />
$(&#8220;#response&#8221;).fadeIn(&#8220;slow&#8221;);<br />
$(&#8220;#response&#8221;).html(html);<br />
setTimeout(&#8216;$(&#8220;#response&#8221;).fadeOut(&#8220;slow&#8221;)&#8217;,4000);<br />
}<br />
});<br />
}</strong></p></blockquote>
<p>This is the &#8220;<strong>core</strong>&#8221; of the script, this will call th<a title="ajax" href="http://docs.jquery.com/Ajax" target="_blank">e</a><strong><a title="ajax" href="http://docs.jquery.com/Ajax" target="_blank"> $.ajax function of Jquery</a>,</strong> give it the parameters and call the <strong>mail.php</strong> file, finally get the response of the <strong>mail.php</strong>, and return this in the response div, and after<strong> 4 seconds the text fade out</strong>. <img src='http://lastwebdesigner.com/wp-includes/images/smilies/icon_smile.gif' alt="icon smile How to send a mail with php ajax and jquery in facebook style" class='wp-smiley' title="How to send a mail with php ajax and jquery in facebook style" /> </p>
<p>This script is inspired ,how I said, from <strong>facebook message system</strong> and it works at the same way, you can use on your own and change or modify the source code.</p>
<p><a class="demo" title="send a mail with php ajax and jquery" href="http://lastwebdesigner.com/tests/mail-jquery-php-ajax/"><strong>Demo of the script</strong></a></p>
<p><a class="download" title="download the full script" href="http://www.box.net/shared/kklgtosti5"><strong>Download directly the script.</strong></a><br />
I hope is useful , you can use the comments and let me know what do you thing.</p>
<p>If you know something to improve the script, let me know pls.</p>
<p>Bye !!</p>
]]></content:encoded>
			<wfw:commentRss>http://lastwebdesigner.com/featured/how-to-send-a-mail-with-php-ajax-and-jquery-in-facebook-style.html/feed</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
		<item>
		<title>Simple animated menu with jquery</title>
		<link>http://lastwebdesigner.com/tutorials/simple-animated-menu-with-jquery.html</link>
		<comments>http://lastwebdesigner.com/tutorials/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[Tutorials]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[downloads]]></category>
		<category><![CDATA[Jquery]]></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 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Flastwebdesigner.com%2Ftutorials%2Fsimple-animated-menu-with-jquery.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Flastwebdesigner.com%2Ftutorials%2Fsimple-animated-menu-with-jquery.html&amp;style=normal&amp;service=bit.ly&amp;hashtags=CSS,downloads,Jquery,menu,tutorial&amp;b=2" height="61" width="50" title="Simple animated menu with jquery" alt=" Simple animated menu with jquery" /><br />
			</a>
		</div>
<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="icon smile Simple animated menu with jquery" 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></p>
]]></content:encoded>
			<wfw:commentRss>http://lastwebdesigner.com/tutorials/simple-animated-menu-with-jquery.html/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

