本文實例講述了基於jQuery實現的向下滑動二級選單效果代碼。分享給大家供大家參考。具體如下:
這是一款使用jQuery製作向下滑動的二級選單,本二級選單帶有動畫效果,而且比較流暢,滑鼠放在一級選單上,就可以向下滑出二級子選單,相對實用。
運作效果截圖如下:
線上示範網址如下:
http://demo.jb51.net/js/2015/jquery-show-down-style-menu-codes/
具體程式碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>向下滑动的二级菜单</title> <style type="text/css"> body{ margin:0px; padding:0px; font-family: Arial, Helvetica, sans-serif; background-color:#dedede; color:#333333; position:relative;} a{ text-decoration:none;} h1,h2,h3,li,ul,dd,dt,dl,input{ margin:0px; padding:0px; list-style:none;} .clear{ clear:both; width:0px; height:0px; line-height:0px; overflow:hidden; font-size:0px; display:block;} img {border: none;} .top{ width:890px; height:68px; margin:0px auto; padding:10px 0px 2px 0px; background-color:#FFFFFF;} .logo{ width:269px; height:68px; padding:0px 8px 0px 3px; float:left;} .logo h1{ width:269px; height:68px; background-image:url(images/logo.gif); background-repeat:no-repeat;} .logo h1 a{ display:block; width:269px; height:68px; line-height:68px; font-size:14px; text-indent:-999px;} .topad{ width:610px; height:68px; float:left;} .dh{ width:890px; height:39px;margin:0px auto; background-image:url(images/nvabg.gif); background-repeat:repeat-x;} .nav{ width:785px; height:38px; padding:1px 0px 0px 15px; float:left;} .nav li{ height:38px; line-height:38px; float:left; font-size:14px; padding:0px 20px; color:#FFFFFF; position:relative;} .nav li a{ color:#FFFFFF;} .nav li a:hover{ text-decoration:underline; font-size:16px;} .nav li .ttg{ height:auto; background-color:#FFFFFF; FILTER: alpha(opacity=80); opacity: 0.8; -moz-opacity: 0.8; position:absolute; left:0px; top:37px; z-index:1; width:150px; padding:10px 0px; -webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; box-shadow:2px 2px 3px #666666; display:none;} .nav li .ttg li{ width:120px; line-height:30px; font-size:16px; padding:0px 10px; font-family:"微软雅黑";} .nav li .ttg li a{ color:#000;} .sc{ width:90px; height:38px; line-height:38px; float:left; font-size:14px; color:#FFFFFF; text-align:center;} .sc a{ color:#FFFFFF;} .sc a:hover{ text-decoration:underline;} .ad{ width:890px; height:auto; margin:10px auto;} .ad img{ float: left; width:445px; overflow:hidden;} </style> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".nav li").hover(function(){ $(this).find(".ttg").slideToggle(500); }); }); </script> </head> <body> <div class="top"> <div class="logo"><h1><a href="#" title="">网站标题文字</a></h1></div> <div class="topad"></div> <div class="clear"></div> </div> <div class="dh"> <div class="nav"> <ul> <li><a href="#" title="首页">首页</a> <div class="ttg"> <ul> <li><a href="#" title="蛋白粉">蛋白粉</a></li> <li><a href="#" title="健身计划">健身计划</a></li> <li><a href="#" title="热门标签">热门标签</a></li> </ul> </div> </li> <li><a href="#" title="蛋白粉">蛋白粉</a> <div class="ttg"> <ul> <li><a href="#" title="蛋白粉">乳清蛋白粉</a></li> <li><a href="#" title="热门标签">增肌粉</a></li> </ul> </div> </li> <li><a href="#" title="健身计划">健身计划</a> <div class="ttg"> <ul> <li><a href="#" title="蛋白粉">胸肌锻炼</a></li> <li><a href="#" title="热门标签">小腿锻炼</a></li> <li><a href="#" title="热门标签">腹肌锻炼</a></li> </ul> </div> </li> </ul> </div> <div class="clear"></div> </div> </body> </html>
希望本文所述對大家的jquery程式設計有所幫助。