`
kevin-qingzhan
  • 浏览: 84133 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

jquery 导航 代码

阅读更多
html代码:

<html>
<head>
<link rel="stylesheet" type="text/css" href="jquerycssmenu.css" />

<!--[if lte IE 7]>
<style type="text/css">
html .jquerycssmenu{height: 1%;}
</style>
<![endif]-->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="jquerycssmenu.js"></script>

</head>


<body>
<div id="myjquerymenu" class="jquerycssmenu">
<ul>

<li><a href="#">Folder 1</a>
  <ul>
  <li><a href="#">Sub Item 1.1</a></li>
  <li><a href="#">Sub Item 1.2</a></li>
  <li><a href="#">Sub Item 1.3</a></li>
  <li><a href="#">Sub Item 1.4</a></li>
  </ul>
</li>
<li><a href="#">Folder 1</a></li>
  </ul>

</div>

</body>
</html>



jquerycssmenu.js代码:



//Specify full URL to down and right arrow images (25 is padding-right to add to top level LIs with drop downs):
var arrowimages={down:['downarrowclass', 'arrow-down.gif', 25], right:['rightarrowclass', 'arrow-right.gif']}

var jquerycssmenu={

fadesettings: {overduration: 350, outduration: 100}, //duration of fade in/ out animation, in milliseconds

buildmenu:function(menuid, arrowsvar){
jQuery(document).ready(function($){
  var $mainmenu=$("#"+menuid+">ul")
  var $headers=$mainmenu.find("ul").parent()
  $headers.each(function(i){
   var $curobj=$(this)
   var $subul=$(this).find('ul:eq(0)')
   this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
   this.istopheader=$curobj.parents("ul").length==1? true : false
   $subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
   $curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
    '<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
    +'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
    + '" style="border:0;" />'
   )
   $curobj.hover(
    function(e){
     var $targetul=$(this).children("ul:eq(0)")
     this._offsets={left:$(this).offset().left, top:$(this).offset().top}
     var menuleft=this.istopheader? 0 : this._dimensions.w
     menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
     $targetul.css({left:menuleft+"px"}).fadeIn(jquerycssmenu.fadesettings.overduration)
    },
    function(e){
     $(this).children("ul:eq(0)").fadeOut(jquerycssmenu.fadesettings.outduration)
    }
   ) //end hover
  }) //end $headers.each()
  $mainmenu.find("ul").css({display:'none', visibility:'visible'})
}) //end document.ready
}
}

//build menu with ID="myjquerymenu" on page:
jquerycssmenu.buildmenu("myjquerymenu", arrowimages)







jquerycssmenu.css代码:

.jquerycssmenu{
font: bold 12px Verdana;
border-bottom: 1px solid black;
padding-left: 15px;
}

.jquerycssmenu ul{
margin: 0;
padding: 0;
list-style-type: none;
}


.jquerycssmenu ul li{
position: relative;
display: inline;
float: left;
}


.jquerycssmenu ul li a{
display: block;
background: white url(tintblue.gif) top center repeat-x;;
padding: 5px 7px 4px 7px;
margin-right: 3px;
border: 1px solid #778;
border-bottom-width: 0;
color: #2d2b2b;
text-decoration: none;
}

.jquerycssmenu ul li a:hover{
background-image: url(tintbluedark.gif)
}
 

.jquerycssmenu ul li ul{
position: absolute;
left: 0;
display: block;
visibility: hidden;
border-top: 1px solid black;
}


.jquerycssmenu ul li ul li{
display: list-item;
float: none;
}


.jquerycssmenu ul li ul li ul{
top: 0;
}


.jquerycssmenu ul li ul li a{
font: normal 13px Verdana;
width: 160px;
background: white;
color: black;
padding: 4px 5px;
margin: 0;
border-top-width: 0;
border-bottom: 1px solid black;
}

.jquerycssmenu ul li ul li a:hover{
background: #eff9ff;
color: black;
}



.downarrowclass{
position: absolute;
top: 7px;
right: 5px;
}

.rightarrowclass{
position: absolute;
top: 5px;
right: 5px;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics