Menu horizontal com jQuery

 

Menu horizontal com jQuery

Neste artigo trago um exemplo de como montar um menu simples e com efeito muito legal similar ao do flash, utilizando apenas CSS e jQuery.
Lembrando que é necessário baixar os plugins jquery e jquery-ui em: http://jquery.com.
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4. <title>Menu Horizontal</title>
  5. <style type="text/css">
  6. ul{
  7.     list-style:none;
  8.     margin:0px;
  9.     margin-top:5px;
  10.     padding:0px;
  11. }
  12. li{
  13.     display:inline;
  14.     font-size:1.1em;
  15.     letter-spacing:-1px;
  16.     font-weight:normal;
  17.     color:#FFF;
  18.     text-align:center;
  19.     float:left;
  20. }
  21. li a{
  22.     display:block;
  23.     color:#FFF;
  24.     background-color:#7EBF00;
  25.     text-decoration:none;
  26.     padding-bottom:10px;
  27.     padding-left:10px;
  28.     padding-right:10px;
  29.     padding-top:10px;
  30. }
  31. </style>
  32. <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
  33. <script type="text/javascript" src="jquery-ui-1.8.2.custom.min.js"></script>
  34. <script type="text/javascript">
  35. $('document').ready(function(){
  36.     //--- Menu
  37.     $('ul a').each(function(key){
  38.         if(key == 0)
  39.             $(this).stop().animate({backgroundColor:"#4F8600"}, {duration:1000});
  40.     });
  41.    
  42.     //--- menu
  43.     $('ul a').hover(
  44.         function(){
  45.             $('ul a').each(function(key){
  46.                 $(this).stop().animate({backgroundColor:"#7EBF00"}, {duration:1500})
  47.             });
  48.            
  49.             $(this).stop().animate({backgroundColor:"#4F8600"}, {duration:1000});
  50.         },
  51.         function(){           
  52.             $('ul a').each(function(key){
  53.                 if(key == 0)
  54.                     $(this).stop().animate({backgroundColor:"#4F8600"}, {duration:800});
  55.                 else
  56.                 {
  57.                     $(this).stop().animate({backgroundColor:"#7EBF00"}, {duration:1500})
  58.                 }
  59.             });
  60.         }
  61.     );
  62. });
  63. </script>
  64. </head>
  65. <body>
  66. <div id="Menu">
  67.     <ul>
  68.            <li><a href="#">Link 1</a></li>
  69.         <li><a href="#">Link 2</a></li>
  70.            <li><a href="#">Link 3</a></li>
  71.     </ul>
  72. </div>
  73. </body>
  74. </html>


Anterior Proxima Página inicial