先给大家展示下效果图,如果大家感觉还不错的话,请参考实现代码。
HTML代码:
js代码:
<script type="text/javascript" src="js/jquery-1.12.3.min.js?1.1.9">《script》 <script type="text/javascript"> $(function(){ $("li").has("ul").mouseover(function(){ $(this).children("ul").css("display","block"); $(this).css("backgroundColor","#0066FF"); }).mouseout(function () { $(this).children("ul").css("display","none"); $(this).css("backgroundColor","#eee"); }) }) 《script》
css代码:
*{ padding:0; margin:0; } /*一级菜单*/ .navMenu { width:570px; margin:0 auto; } .navMenu ul li{ float: left; position: relative; } li{ list-style: none; background-color: #eee; width: 140px; height: 40px; text-align: center; margin-right: 2px; margin-bottom: 2px; } ul li a{ line-height: 40px; text-align: center; font-size: 20px; color: #000; text-decoration: none; display: block; padding:0 10px; } /*二级菜单*/ .navMenu ul li ul { display: none; position:absolute; left: 0; top:0; margin-top:42px; } .navMenu ul li ul li{ float:none; } /*三级菜单*/ .navMenu ul li ul li ul{ display: none; left:140px; top:-42px; }
以上内容是小编给大家介绍的jQuery实现三级菜单的代码,希望对大家有所帮助!