<?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>David Rojas &#187; jQuery</title>
	<atom:link href="http://www.davidrojas.net/index.php/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidrojas.net</link>
	<description>Diseño y desarrollo web</description>
	<lastBuildDate>Fri, 23 Jul 2010 21:31:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Videotutorial: Cómo hacer un plugin jQuery &#8211; Menú acordeón multinivel</title>
		<link>http://www.davidrojas.net/index.php/jquery/screencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel/</link>
		<comments>http://www.davidrojas.net/index.php/jquery/screencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 18:39:11 +0000</pubDate>
		<dc:creator>David Rojas</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Desarrollo Web]]></category>
		<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.davidrojas.net/?p=704</guid>
		<description><![CDATA[Respondiendo a la multitud de peticiones en los comentarios del artículo sobre cómo crear un menú en acordeón, aquí os muestro cómo hacer el mismo menú pero con soporte para varios niveles.
Este menú está basado en el anterior, y como apenas necesitaba un pequeño cambio en el javascript para hacerlo multinivel, he aprovechado para convertirlo [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.davidrojas.net/wp-content/uploads/2010/03/jquery_accordion_screencast.png" alt="" title="jquery_accordion_screencast" width="163" height="104" class="derecha alignright size-full wp-image-718" />Respondiendo a la multitud de peticiones en los comentarios del artículo sobre <a href="http://www.davidrojas.net/index.php/diseno-web/menu-vertical-en-acordeon-con-css-y-jquery/" title="Menú vertical en acordeón con CSS y jQuery">cómo crear un menú en acordeón</a>, aquí os muestro cómo hacer el mismo menú pero con soporte para varios niveles.<br />
Este menú está basado en el anterior, y como apenas necesitaba un pequeño cambio en el javascript para hacerlo multinivel, he aprovechado para convertirlo en un plugin y enseñaros en un screencast cómo hacer vuestros propios plugins en jQuery.</p>
<p><em class="linkem"><a href='http://www.davidrojas.net/demos/acordeon_multinivel.html' title="Demo menú vertical en acordeón multinivel" target="_blank">Ver Demo menú acordeón multinivel</a></em><br />
<span id="more-704"></span></p>
<h3>Ver screencast (duración: 8:17)</h3>
<div class="video">
<embed src="http://blip.tv/play/hJIhgcqcaQA" type="application/x-shockwave-flash" width="490" height="397" allowscriptaccess="always" allowfullscreen="true"></embed>
</div>
<ul>
<li><a href="http://blip.tv/file/get/Davidrojas-7CmoHacerUnPluginJQueryMenAcordenMultinivel831.mov" title="Descargar versión alta calidad">Descargar videotutorial en alta calidad &#8211; MOV (25 MB)</a></li>
<li><a href="http://blip.tv/file/get/Davidrojas-7CmoHacerUnPluginJQueryMenAcordenMultinivel409.m4v" title="Descargar versión iPod/iPhone">Descargar videotutorial optimizado para iPod/iPhone &#8211; M4V (13 MB)</a></li>
</ul>
<p></p>
<p>No olvidéis echarle un vistazo al resto de videos en la <a href="http://www.davidrojas.net/index.php/category/screencasts/" title="Videotutoriales de diseño, desarrollo web, jquery, codeigniter, CSS3">página de videotutoriales</a>, o suscribiros al <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=326994250" title="Enlace a videopodcast de David Rojas en iTunes">podcast de iTunes</a>.</p>
<h3>Cómo usarlo</h3>
<p>Para ver el HTML y CSS no tenéis mas que ver el código fuente del ejemplo de arriba, es bastante similar al del artículo anterior. En el html se añade un nivel más de anidamiento de listas, y en el CSS se le añade la regla <code>#menu ul li li{padding-left: 10px;}</code> para que los niveles inferiores tengan padding (esto podéis modificarlo como queráis).<br />
Para cargar el javascript, podéis copiar el código en la cabecera tal como está en el ejemplo, o bien <em class="linkem"><a href='http://www.davidrojas.net/wp-content/uploads/2010/03/jquery.accordion.js'>descargaros el archivo JS con el plugin</a></em> e insertarlo de esta manera:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.accordion.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Después sólo os queda llamar al plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#menu'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">accordion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p></p>

<div class="sociable">
<div class="sociable_tagline">
<em>Si te ha gustado este artículo, por favor compártelo:</em>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;partner=sociable" title="Print"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;title=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel&amp;bodytext=Respondiendo%20a%20la%20multitud%20de%20peticiones%20en%20los%20comentarios%20del%20art%C3%ADculo%20sobre%20c%C3%B3mo%20crear%20un%20men%C3%BA%20en%20acorde%C3%B3n%2C%20aqu%C3%AD%20os%20muestro%20c%C3%B3mo%20hacer%20el%20mismo%20men%C3%BA%20pero%20con%20soporte%20para%20varios%20niveles.%0D%0AEste%20men%C3%BA%20est%C3%A1%20basado%20en%20el%20anterior%2C%20y%20como%20apena" title="Digg"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;title=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel&amp;notes=Respondiendo%20a%20la%20multitud%20de%20peticiones%20en%20los%20comentarios%20del%20art%C3%ADculo%20sobre%20c%C3%B3mo%20crear%20un%20men%C3%BA%20en%20acorde%C3%B3n%2C%20aqu%C3%AD%20os%20muestro%20c%C3%B3mo%20hacer%20el%20mismo%20men%C3%BA%20pero%20con%20soporte%20para%20varios%20niveles.%0D%0AEste%20men%C3%BA%20est%C3%A1%20basado%20en%20el%20anterior%2C%20y%20como%20apena" title="del.icio.us"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;t=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel" title="Facebook"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;title=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel&amp;annotation=Respondiendo%20a%20la%20multitud%20de%20peticiones%20en%20los%20comentarios%20del%20art%C3%ADculo%20sobre%20c%C3%B3mo%20crear%20un%20men%C3%BA%20en%20acorde%C3%B3n%2C%20aqu%C3%AD%20os%20muestro%20c%C3%B3mo%20hacer%20el%20mismo%20men%C3%BA%20pero%20con%20soporte%20para%20varios%20niveles.%0D%0AEste%20men%C3%BA%20est%C3%A1%20basado%20en%20el%20anterior%2C%20y%20como%20apena" title="Google Bookmarks"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel&amp;body=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F" title="email"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://meneame.net/submit.php?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F" title="Meneame"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/meneame.png" title="Meneame" alt="Meneame" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;title=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel" title="StumbleUpon"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F&amp;t=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel&amp;s=Respondiendo%20a%20la%20multitud%20de%20peticiones%20en%20los%20comentarios%20del%20art%C3%ADculo%20sobre%20c%C3%B3mo%20crear%20un%20men%C3%BA%20en%20acorde%C3%B3n%2C%20aqu%C3%AD%20os%20muestro%20c%C3%B3mo%20hacer%20el%20mismo%20men%C3%BA%20pero%20con%20soporte%20para%20varios%20niveles.%0D%0AEste%20men%C3%BA%20est%C3%A1%20basado%20en%20el%20anterior%2C%20y%20como%20apena" title="Tumblr"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Videotutorial%3A%20C%C3%B3mo%20hacer%20un%20plugin%20jQuery%20-%20Men%C3%BA%20acorde%C3%B3n%20multinivel%20-%20http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fjquery%2Fscreencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel%2F" title="Twitter"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidrojas.net/index.php/jquery/screencast-como-hacer-un-plugin-jquery-menu-acordeon-multinivel/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Menú vertical en acordeón con CSS y jquery</title>
		<link>http://www.davidrojas.net/index.php/diseno-web/menu-vertical-en-acordeon-con-css-y-jquery/</link>
		<comments>http://www.davidrojas.net/index.php/diseno-web/menu-vertical-en-acordeon-con-css-y-jquery/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:16:00 +0000</pubDate>
		<dc:creator>David Rojas</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Desarrollo Web]]></category>
		<category><![CDATA[Diseño Web]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.davidrojas.net/?p=396</guid>
		<description><![CDATA[A pesar del buen feedback recibido sobre mi serie de tutoriales de CodeIgniter, los artículos sobre menús animados con CSS y javascript siguen siendo los más populares en este sitio, y parece que son bastante útiles para la gente que está empezando. Por ello hoy me tomo un pequeño respiro de los videotutoriales y voy [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.davidrojas.net/wp-content/uploads/2009/10/menu_acordeon.png" alt="menu_acordeon" title="menu_acordeon" width="156" height="120" class="derecha alignright size-full wp-image-430" />A pesar del buen <em>feedback</em> recibido sobre mi serie de <a href="http://www.davidrojas.net/index.php/category/codeigniter/">tutoriales de CodeIgniter</a>, los artículos sobre <a href="http://www.davidrojas.net/index.php/diseno-web/menu-animado-desplegable-con-css-y-jquery/">menús animados con CSS y javascript</a> siguen siendo los más populares en este sitio, y parece que son bastante útiles para la gente que está empezando. Por ello hoy me tomo un pequeño respiro de los videotutoriales y voy a enseñaros cómo hacer el clásico menú vertical en acordeón con CSS y jQuery.<br />
El resultado lo puedes ver aquí: <em class="linkem"><a href="http://www.davidrojas.net/demos/menu_acordeon.html" target="_blank">Ver demo</a></em><br />
<span id="more-396"></span></p>
<h3>HTML</h3>
<p>Para el html del menú vamos a emplear la estructura típica de listas anidadas. La última entrada será un enlace directo, sin submenú:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;menu&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu sin submenu<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<h3>Añadiendo el CSS</h3>
<p>Para dar estilo al menú tenemos primero que quitar los estilos por defecto de las listas, eliminar los bullets y márgenes y añadirle <em>display:block</em> para que queden perfectamente alineados los elementos uno debajo de otro. Después tenemos que ocultar con <em>display:none</em> los submenús para que aparezcan todos colapsados por defecto. Vamos a añadir algunas extensiones de CSS3 para mejorar visualmente nuestro menú. Estás extensiones sólo serán visibles en navegadores modernos (Firefox, Chrome y Safari), pero no en Internet Explorer. De esta manera podemos añadir bordes redondeados y sombras al menú y al texto. La propiedad <em>-webkit-transition</em> solo funciona en navegadores basados en webkit (Safari y Chrome), y la utilizaremos para mejor el hover añadiendo un fundido en el color del texto y el background. En los navegadores que no soporten estas propiedades simplemente veremos el menú con esquinas normales, hover típico on-off de CSS y sin sombras.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#menu</span><span style="color: #00AA00;">&#123;</span>
	-moz-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	-webkit-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	-webkit-box-shadow<span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#888</span><span style="color: #00AA00;">;</span>
	-moz-box-shadow<span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#888</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> li<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> ul li<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#menu</span> li<span style="color: #3333ff;">:last-child</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">&#125;</span>	
a<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span><span style="color: #ff0000;">'Helvetica'</span><span style="color: #00AA00;">,</span> Arial<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#325179</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F9B855</span><span style="color: #00AA00;">;</span>
	-webkit-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">color</span> 0.2s linear<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> ul a<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#6594D1</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> ul a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#2961A9</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
	-webkit-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">background-color</span> 0.2s linear<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ul<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#2961A9</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">130px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> ul<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#6594D1</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#menu</span> li ul <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>Añadiendo la funcionalidad con jQuery</h3>
<p>Ahora vamos a ver lo sencillo que es hacer funcionar nuestro menú vertical. Primero añadimos el evento <em>click</em> a cada enlace del menú. Después comprobamos si el siguiente elemento tras el enlace es un <em>ul</em>, ya que si es así este contendrá un submenú, si no será un elemento de un submenú o bien un elemento principal que no contiene submenú (en nuestro ejemplo, el último enlace). Si contiene un submenú, al hacer click este se expandirá o colapsará (<em>slideToggle()</em>), a la vez que colapsaremos el submenú que esté visible que no sea el actual. La función <em>event.preventDefault()</em> sirve para evitar que cuando hagamos click el navegador siga el enlace del <em>href</em> tras ejecutar nuestra función javascript.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#menu li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> elem <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>elem.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			event.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#menu ul:visible'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">not</span><span style="color: #009900;">&#40;</span>elem<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			elem.<span style="color: #660066;">slideToggle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Podéis escribir en los comentarios cualquier duda que tengáis e intentaré responderla, así como sugerencias para próximos tutoriales.</p>

<div class="sociable">
<div class="sociable_tagline">
<em>Si te ha gustado este artículo, por favor compártelo:</em>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;partner=sociable" title="Print"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;title=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery&amp;bodytext=A%20pesar%20del%20buen%20feedback%20recibido%20sobre%20mi%20serie%20de%20tutoriales%20de%20CodeIgniter%2C%20los%20art%C3%ADculos%20sobre%20men%C3%BAs%20animados%20con%20CSS%20y%20javascript%20siguen%20siendo%20los%20m%C3%A1s%20populares%20en%20este%20sitio%2C%20y%20parece%20que%20son%20bastante%20%C3%BAtiles%20para%20la%20gente%20que%20est%C3%A1%20empeza" title="Digg"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;title=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery&amp;notes=A%20pesar%20del%20buen%20feedback%20recibido%20sobre%20mi%20serie%20de%20tutoriales%20de%20CodeIgniter%2C%20los%20art%C3%ADculos%20sobre%20men%C3%BAs%20animados%20con%20CSS%20y%20javascript%20siguen%20siendo%20los%20m%C3%A1s%20populares%20en%20este%20sitio%2C%20y%20parece%20que%20son%20bastante%20%C3%BAtiles%20para%20la%20gente%20que%20est%C3%A1%20empeza" title="del.icio.us"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;t=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery" title="Facebook"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;title=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery&amp;annotation=A%20pesar%20del%20buen%20feedback%20recibido%20sobre%20mi%20serie%20de%20tutoriales%20de%20CodeIgniter%2C%20los%20art%C3%ADculos%20sobre%20men%C3%BAs%20animados%20con%20CSS%20y%20javascript%20siguen%20siendo%20los%20m%C3%A1s%20populares%20en%20este%20sitio%2C%20y%20parece%20que%20son%20bastante%20%C3%BAtiles%20para%20la%20gente%20que%20est%C3%A1%20empeza" title="Google Bookmarks"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery&amp;body=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F" title="email"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://meneame.net/submit.php?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F" title="Meneame"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/meneame.png" title="Meneame" alt="Meneame" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;title=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery" title="StumbleUpon"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F&amp;t=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery&amp;s=A%20pesar%20del%20buen%20feedback%20recibido%20sobre%20mi%20serie%20de%20tutoriales%20de%20CodeIgniter%2C%20los%20art%C3%ADculos%20sobre%20men%C3%BAs%20animados%20con%20CSS%20y%20javascript%20siguen%20siendo%20los%20m%C3%A1s%20populares%20en%20este%20sitio%2C%20y%20parece%20que%20son%20bastante%20%C3%BAtiles%20para%20la%20gente%20que%20est%C3%A1%20empeza" title="Tumblr"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Men%C3%BA%20vertical%20en%20acorde%C3%B3n%20con%20CSS%20y%20jquery%20-%20http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-vertical-en-acordeon-con-css-y-jquery%2F" title="Twitter"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidrojas.net/index.php/diseno-web/menu-vertical-en-acordeon-con-css-y-jquery/feed/</wfw:commentRss>
		<slash:comments>102</slash:comments>
		</item>
		<item>
		<title>Menú animado desplegable con CSS y jquery</title>
		<link>http://www.davidrojas.net/index.php/diseno-web/menu-animado-desplegable-con-css-y-jquery/</link>
		<comments>http://www.davidrojas.net/index.php/diseno-web/menu-animado-desplegable-con-css-y-jquery/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 20:54:43 +0000</pubDate>
		<dc:creator>David Rojas</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Desarrollo Web]]></category>
		<category><![CDATA[Diseño Web]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.davidrojas.net/?p=202</guid>
		<description><![CDATA[Tras el inesperado éxito de mi artículo Menú animado con CSS y jquery, me he decidido a escribir un nuevo tutorial sobre creación de menús: cómo hacer un menú horizontal animado desplegable con CSS y jquery. Cada elemento del menú horizontal contendrá un submenú vertical que se desplegará con una animación. A su vez, al [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.davidrojas.net/wp-content/uploads/2009/07/menu_desplegable.png" alt="menu_desplegable" title="menu_desplegable" width="200" height="120" class="derecha alignright size-full wp-image-211" />Tras el inesperado éxito de mi artículo <a href="http://www.davidrojas.net/index.php/diseno-web/menu-animado-con-css-y-jquery/">Menú animado con CSS y jquery</a>, me he decidido a escribir un nuevo tutorial sobre creación de menús: cómo hacer un menú horizontal animado desplegable con CSS y jquery. Cada elemento del menú horizontal contendrá un submenú vertical que se desplegará con una animación. A su vez, al pasar el ratón sobre cada entrada del submenú éste cambiará de color de forma gradual. El resultado lo puedes ver aquí: <em style="border-bottom:1px dotted #C00202;"><a href="http://www.davidrojas.net/demos/menu_desplegable.html" target="_blank">Ver demo</a></em><br />
<span id="more-202"></span></p>
<h3>Imágenes</h3>
<p>La única imagen que vamos a utilizar es este gradiente para el fondo de los submenús, que además del efecto relieve que proporciona, nos ayudará a realizar las transiciones del hover.</p>
<p><img class="imgpost alignnone size-full wp-image-94" title="menu_desplegable" src="http://www.davidrojas.net/demos/fondo_menu_desplegable.png" alt="fondo_menu" width="5" height="125" /></p>
<h3>HTML</h3>
<p>El html empleado es una simple lista con otra lista anidada para cada submenú:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nav&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submenu&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submenu&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submenu&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Menu 4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submenu&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Submenu 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<h3>Añadiendo el CSS</h3>
<p>La mayor parte del css son para mejorar el aspecto visual del menú. Funcionalmente, podemos destacar varias cosas. Los elementos de la lista principal (#nav) se encuentran flotados a la izquierda, para formar el menú horizontal, y tienen <em>position: relative</em> para que sirva de referencia a cada submenú. A la lista del submenú le asignamos <em>position: absolute</em>, para que cuando se despliegue esté situada bajo su menú correspondiente. Este submenú lo ocultamos por defecto con <em>display: none</em> para después mostrarlo con javascript cuando pasemos el ratón por encima de su menú padre. A cada enlace del elemento del submenú añadiremos la imagen del gradiente como <em>background</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#004a80</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
ul<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">28px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
ul<span style="color: #00AA00;">,</span>li<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#nav</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">'Century Gothic'</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#nav</span> li<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">125px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-variant</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">small-caps</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#004a80</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#004A80</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
.submenu<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#nav</span> <span style="color: #6666ff;">.submenu</span> li<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">static</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">11px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-variant</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#004a80</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">124px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#nav</span> <span style="color: #6666ff;">.submenu</span> li a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFFFF</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#004a80</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'fondo_menu_vertical.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">114px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>Javascript y jQuery</h3>
<p>Ahora añadiremos la funcionalidad del menú. Para ello necesitaremos primero incluir la librería jQuery, que podemos hacerlo cargándola directamente desde el repositorio de Google:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>También necesitaremos añadir el <a href="http://plugins.jquery.com/project/backgroundPosition-Effect" rel="nofollow">plugin backgroundPosition</a> para jQuery, ya que éste no soporta de serie la animación de la propiedad <em>background-position</em>. Lo descargaremos y añadiremos así:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jquery.backgroundPosition.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p>Finalmente, con unas pocas líneas de código, usando la función <em>slideDown/slideUp</em> y el evento <em>hover</em> mostraremos el submenú correspondiente cuando pasemos el ratón por uno de los elementos del menú principal. Usando la función <em>animate</em>, al pasar el ratón por encima de cada entrada del submenú se cambiará la propiedad <em>background-position</em>, deslizando la imagen del gradiente y creando un efecto de fundido rápido, para que la transición sea más suave que si utilizáramos simplemente <em>a:hover</em> para cambiar el color de fondo del enlace activo.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav&gt;li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.submenu'</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.submenu'</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.submenu li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0px 0px&quot;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;(0px -99px)&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">250</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>backgroundPosition<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;(0px 0px)&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">250</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>


<div class="sociable">
<div class="sociable_tagline">
<em>Si te ha gustado este artículo, por favor compártelo:</em>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;partner=sociable" title="Print"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery&amp;bodytext=Tras%20el%20inesperado%20%C3%A9xito%20de%20mi%20art%C3%ADculo%20Men%C3%BA%20animado%20con%20CSS%20y%20jquery%2C%20me%20he%20decidido%20a%20escribir%20un%20nuevo%20tutorial%20sobre%20creaci%C3%B3n%20de%20men%C3%BAs%3A%20c%C3%B3mo%20hacer%20un%20men%C3%BA%20horizontal%20animado%20desplegable%20con%20CSS%20y%20jquery.%20Cada%20elemento%20del%20men%C3%BA%20horizontal%20" title="Digg"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery&amp;notes=Tras%20el%20inesperado%20%C3%A9xito%20de%20mi%20art%C3%ADculo%20Men%C3%BA%20animado%20con%20CSS%20y%20jquery%2C%20me%20he%20decidido%20a%20escribir%20un%20nuevo%20tutorial%20sobre%20creaci%C3%B3n%20de%20men%C3%BAs%3A%20c%C3%B3mo%20hacer%20un%20men%C3%BA%20horizontal%20animado%20desplegable%20con%20CSS%20y%20jquery.%20Cada%20elemento%20del%20men%C3%BA%20horizontal%20" title="del.icio.us"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;t=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery" title="Facebook"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery&amp;annotation=Tras%20el%20inesperado%20%C3%A9xito%20de%20mi%20art%C3%ADculo%20Men%C3%BA%20animado%20con%20CSS%20y%20jquery%2C%20me%20he%20decidido%20a%20escribir%20un%20nuevo%20tutorial%20sobre%20creaci%C3%B3n%20de%20men%C3%BAs%3A%20c%C3%B3mo%20hacer%20un%20men%C3%BA%20horizontal%20animado%20desplegable%20con%20CSS%20y%20jquery.%20Cada%20elemento%20del%20men%C3%BA%20horizontal%20" title="Google Bookmarks"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery&amp;body=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F" title="email"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://meneame.net/submit.php?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F" title="Meneame"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/meneame.png" title="Meneame" alt="Meneame" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery" title="StumbleUpon"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F&amp;t=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery&amp;s=Tras%20el%20inesperado%20%C3%A9xito%20de%20mi%20art%C3%ADculo%20Men%C3%BA%20animado%20con%20CSS%20y%20jquery%2C%20me%20he%20decidido%20a%20escribir%20un%20nuevo%20tutorial%20sobre%20creaci%C3%B3n%20de%20men%C3%BAs%3A%20c%C3%B3mo%20hacer%20un%20men%C3%BA%20horizontal%20animado%20desplegable%20con%20CSS%20y%20jquery.%20Cada%20elemento%20del%20men%C3%BA%20horizontal%20" title="Tumblr"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Men%C3%BA%20animado%20desplegable%20con%20CSS%20y%20jquery%20-%20http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-desplegable-con-css-y-jquery%2F" title="Twitter"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidrojas.net/index.php/diseno-web/menu-animado-desplegable-con-css-y-jquery/feed/</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
		<item>
		<title>Menú animado con CSS y jquery</title>
		<link>http://www.davidrojas.net/index.php/diseno-web/menu-animado-con-css-y-jquery/</link>
		<comments>http://www.davidrojas.net/index.php/diseno-web/menu-animado-con-css-y-jquery/#comments</comments>
		<pubDate>Sun, 17 May 2009 11:32:52 +0000</pubDate>
		<dc:creator>David Rojas</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Desarrollo Web]]></category>
		<category><![CDATA[Diseño Web]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.davidrojas.net/?p=90</guid>
		<description><![CDATA[La diferencia entre un buen diseño y un diseño genial puede estar en pequeños detalles que proporcionen mayor riqueza visual, como los menús animados realizados habitualmente en Adobe Flash. Como no soy amigo del Flash (*insertar aquí delirio sobre porqué los desarrolladores serios odiamos flash*), voy a mostraros cómo hacer un menú similar al que [...]]]></description>
			<content:encoded><![CDATA[<p>La diferencia entre un buen diseño y un diseño genial puede estar en pequeños detalles que proporcionen mayor riqueza visual, como los menús animados realizados habitualmente en Adobe Flash. Como no soy amigo del Flash (*insertar aquí delirio sobre porqué los desarrolladores serios odiamos flash*), voy a mostraros cómo hacer un menú similar al que tenemos en la cabecera de esta web usando CSS Sprites y javascript (jQuery).</p>
<h3>Preparando las imágenes</h3>
<p>En primer lugar montaremos los tres estados del botón (normal, hover y activo) en un sprite tal que así:</p>
<p><img class="imgpost alignnone size-full wp-image-94" title="homeboton" src="http://www.davidrojas.net/wp-content/uploads/2009/05/homeboton.png" alt="homeboton" width="76" height="90" /></p>
<p>La técnica de sprites consiste en utilizar una única imagen para todos los casos, mostrando sólo la parte que nos interesa mediante la propiedad <em>background-position</em>. La altura de la imagen es de 30px, de manera que para mostrar cada bloque cambiaremos la posición vertical del fondo a 0, 30px o 60px según el fragmento.<br />
<span id="more-90"></span></p>
<h3>Las etiquetas XHTML</h3>
<p>Al contrario que en otras soluciones de menús animados que podemos encontrar por la red, en este método únicamente vamos a usar el markup necesario, no añadiremos etiquetas <em>&lt;span&gt;</em> vacías extra para añadir funcionalidad. Para simplificar incluiremos solo el elemento del &#8216;Home&#8217;:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nav&quot;</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;home&quot;</span>&gt;</span>
     <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span>&gt;</span>Home<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<h3>Añadiendo el CSS</h3>
<p>Haremos que tanto el <em>&lt;li&gt;</em> como el <em>&lt;a&gt;</em> sean de la misma medida fija, para poder jugar con la posición del <em>background</em>. Indentamos el texto para hacerlo desaparecer, de esta manera el menú será completamente accesible y semántico.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">ul<span style="color: #cc00cc;">#nav</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">transparent</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/menu.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ul<span style="color: #cc00cc;">#nav</span><span style="color: #00AA00;">,</span> ul<span style="color: #cc00cc;">#nav</span> li<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">83px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ul<span style="color: #cc00cc;">#nav</span> li<span style="color: #cc00cc;">#home</span> a<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">83px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span><span style="color: #933;">-9999px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background-image</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/menu.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">bottom</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
ul<span style="color: #cc00cc;">#nav</span> li<span style="color: #cc00cc;">#home</span> a<span style="color: #3333ff;">:active</span><span style="color: #00AA00;">,</span> ul<span style="color: #cc00cc;">#nav</span> li.activo<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'images/menu.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">0px</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>El <em>background</em> del <em>&lt;ul&gt;</em> mostrará la parte superior de la imagen, es decir el estado normal del botón. El enlace contendrá la parte inferior, desplazada mediante el <em>background-position</em>, y permanecerá oculto con javascript hasta que pasemos el ratón por encima. Finalmente el <em>&lt;li&gt;</em> solo tendrá <em>background</em> si nos encontramos en la sección activa del menú, o estamos pulsando el botón (pseudoclase <em>:active</em>).</p>
<h3>Entra jQuery</h3>
<p>Y ahora viene la madre del cordero, un poco de &#8216;jQuery magic&#8217;:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ul#nav li a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;opacity&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// on mouse over</span>
	        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> opacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #006600; font-style: italic;">// on mouse out</span>
	<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> opacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Sencillo, ¿verdad? Simplemente cambiamos la opacidad del enlace a 0 al cargar, para que no veamos el fondo que contiene el fragmento hover de la imagen. Después adjuntamos el evento para aumentar la opacidad del enlace hasta hacer visible su fondo cuando pasamos el ratón por encima, realizando la operación inversa al retirar el ratón.<br />
Como puedes ver el funcionamiento de este menú se basa en aprovechar la jerarquía de la lista del menú, apilando fondos en el &lt;ul&gt;, &lt;li&gt; y &lt;a&gt; y mostrando el que nos interesa.</p>

<div class="sociable">
<div class="sociable_tagline">
<em>Si te ha gustado este artículo, por favor compártelo:</em>
</div>
<ul>
	<li class="sociablefirst"><a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;partner=sociable" title="Print"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20con%20CSS%20y%20jquery&amp;bodytext=La%20diferencia%20entre%20un%20buen%20dise%C3%B1o%20y%20un%20dise%C3%B1o%20genial%20puede%20estar%20en%20peque%C3%B1os%20detalles%20que%20proporcionen%20mayor%20riqueza%20visual%2C%20como%20los%20men%C3%BAs%20animados%20realizados%20habitualmente%20en%20Adobe%20Flash.%20Como%20no%20soy%20amigo%20del%20Flash%20%28%2Ainsertar%20aqu%C3%AD%20delirio%20so" title="Digg"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20con%20CSS%20y%20jquery&amp;notes=La%20diferencia%20entre%20un%20buen%20dise%C3%B1o%20y%20un%20dise%C3%B1o%20genial%20puede%20estar%20en%20peque%C3%B1os%20detalles%20que%20proporcionen%20mayor%20riqueza%20visual%2C%20como%20los%20men%C3%BAs%20animados%20realizados%20habitualmente%20en%20Adobe%20Flash.%20Como%20no%20soy%20amigo%20del%20Flash%20%28%2Ainsertar%20aqu%C3%AD%20delirio%20so" title="del.icio.us"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;t=Men%C3%BA%20animado%20con%20CSS%20y%20jquery" title="Facebook"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20con%20CSS%20y%20jquery&amp;annotation=La%20diferencia%20entre%20un%20buen%20dise%C3%B1o%20y%20un%20dise%C3%B1o%20genial%20puede%20estar%20en%20peque%C3%B1os%20detalles%20que%20proporcionen%20mayor%20riqueza%20visual%2C%20como%20los%20men%C3%BAs%20animados%20realizados%20habitualmente%20en%20Adobe%20Flash.%20Como%20no%20soy%20amigo%20del%20Flash%20%28%2Ainsertar%20aqu%C3%AD%20delirio%20so" title="Google Bookmarks"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="mailto:?subject=Men%C3%BA%20animado%20con%20CSS%20y%20jquery&amp;body=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F" title="email"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://meneame.net/submit.php?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F" title="Meneame"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/meneame.png" title="Meneame" alt="Meneame" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;title=Men%C3%BA%20animado%20con%20CSS%20y%20jquery" title="StumbleUpon"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a></li>
	<li><a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F&amp;t=Men%C3%BA%20animado%20con%20CSS%20y%20jquery&amp;s=La%20diferencia%20entre%20un%20buen%20dise%C3%B1o%20y%20un%20dise%C3%B1o%20genial%20puede%20estar%20en%20peque%C3%B1os%20detalles%20que%20proporcionen%20mayor%20riqueza%20visual%2C%20como%20los%20men%C3%BAs%20animados%20realizados%20habitualmente%20en%20Adobe%20Flash.%20Como%20no%20soy%20amigo%20del%20Flash%20%28%2Ainsertar%20aqu%C3%AD%20delirio%20so" title="Tumblr"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" class="sociable-hovers" /></a></li>
	<li class="sociablelast"><a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Men%C3%BA%20animado%20con%20CSS%20y%20jquery%20-%20http%3A%2F%2Fwww.davidrojas.net%2Findex.php%2Fdiseno-web%2Fmenu-animado-con-css-y-jquery%2F" title="Twitter"><img src="http://www.davidrojas.net/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a></li>
</ul>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.davidrojas.net/index.php/diseno-web/menu-animado-con-css-y-jquery/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
