精华分享一个JQ+CSS写的无限下拉菜单,非常不错

CSS1618浏览0条评论css无限下拉菜单css

我本打算用纯CSS写的,- -写了半天硬是没写出来,网上搜了一下,看到纯CSS写的挺复杂,没办法只有找JQ的了,发现了这个不错,推荐一下,优点在于CSS少,JQ代码也简单,代码结构清晰,本站的无限分类菜单就是用这个改的,可以查看下效果。

效果图:

<!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>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
        $(".catelist1 li").hover(function(){
            $(this).find("ul:first").show();//鼠标滑过查找li下面的第一个ul然后显示;
        },function(){
            $(this).find("ul:first").hide();//鼠标离开隐藏li下面d的ul;
        })
        $(".catelist1 li ul li ul").prev().addClass("show_list");//给li下面ul是aaa的样式的前一个同辈元素添加css;
                
    })
</script>

<style type="text/css">
ul, li{padding:0;margin:0;}
ul li{float:left;;margin-right:1px;display:inline;list-style:none;text-align:center;}
ul li ul li{float:none;background:#ccc;margin-bottom:1px;display:block;_display:inline;position:relative;}
ul li ul{display:none;}
ul a{text-decoration:none;width:80px;height:20px;line-height:20px;display:block;background:#bbb;font-size:12px}
ul li a:hover{background:#eee;color:#000}
ul li ul li .aaa{position:absolute;left:80px;top:0;border-left:1px solid #fff}
ul li ul li .aaa li{float:none;}
body .show_list{background:#39F;color:#fff}

</style>

</head>
<body>

<ul class="catelist1">
   <li>
      <a href="">栏目一</a>
      <ul>
         <li><a href="">菜单一</a></li>
         <li><a href="">菜单一</a></li>
         <li><a href="">菜单一</a></li>
         <li><a href="">菜单一变色</a>
             <ul class="aaa">
                <li><a href="">菜单三</a></li>
                <li><a href="">菜单三</a>
                    <ul class="aaa">
                        <li><a href="">菜单三</a></li>
                        <li><a href="">菜单三</a></li>
                        <li><a href="">菜单三</a>
                            <ul class="aaa">
                                <li><a href="">菜单三</a></li>
                                <li><a href="">菜单三</a></li>
                                <li><a href="">菜单三</a>
                                    <ul class="aaa">
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                     </ul>
                                </li>
                                <li><a href="">菜单三</a></li>
                             </ul>
                        </li>
                        <li><a href="">菜单三</a></li>
                     </ul>
                </li>
                <li><a href="">菜单三</a></li>
                <li><a href="">菜单三</a></li>
             </ul>
         </li>
      </ul>
   </li>
   
   
   
   <li>
      <a href="">栏目二</a>
      <ul class="aaa catelist">
     <li><a href="">aaa</a></li>
      <li><a href="">aaa</a>
      
            <ul class="aaa catelist">
     <li><a href="">bbb</a></li>
      <li><a href="">bbb</a></li>
      </ul>
      </li>
      </ul>
      
   </li>
   
   
   
   
   <li>
      <a href="">栏目三</a>
       <ul>
         <li><a href="">菜单三</a>
         </li>
         <li><a href="">菜单三</a>
             <ul class="aaa">
                <li><a href="">菜单三</a></li>
                <li><a href="">菜单三</a>
                    <ul class="aaa">
                                <li><a href="">菜单三</a></li>
                                <li><a href="">菜单三</a></li>
                                <li><a href="">菜单三</a>
                                    <ul class="aaa">
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                     </ul>
                                </li>
                                <li><a href="">菜单三</a>
                                    <ul class="aaa">
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a>
                                            <ul class="aaa">
                                                <li><a href="">菜单三</a></li>
                                                <li><a href="">菜单三</a></li>
                                                <li><a href="">菜单三</a></li>
                                                <li><a href="">菜单三</a></li>
                                             </ul>
                                        </li>
                                        <li><a href="">菜单三</a></li>
                                        <li><a href="">菜单三</a></li>
                                     </ul>
                                </li>
                             </ul>
                </li>
                <li><a href="">菜单三</a></li>
                <li><a href="">菜单三</a></li>
             </ul>
         </li>
         <li><a href="">菜单三</a></li>
         <li><a href="">菜单三</a></li>
      </ul>
   </li>
   <li>
      <a href="">栏目四</a>
   </li>
</ul>

</body>
</html>


本文地址:http://wuheng.net/blog_26.html 转载请注明出处

分享到: