我有一個jQuery的菜單子菜單。也許是太簡單了,但我只有一點經驗與jQueryjquery保持項目可見,直到選擇另一個項目
我想顯示在鼠標懸停事件的子菜單,並保持可見,直到選擇不同的菜單選項。
我使用jQuery的菜單,我發現在http://www.dynamicdrive.com/style/csslibrary/item/jquery_drop_line_tabs/
這裏是代碼
<script src="droplinemenu.js" type="text/javascript"></script>
<script type="text/javascript">
//build menu with DIV ID="myslidemenu" on page:
droplinemenu.buildmenu("droplinetabs1")
</script>
<div id="droplinetabs1" class="droplinetabs">
<ul>
<li><a href="http://www.dynamicdrive.com/"><span>Home</span></a></li>
<li><a href="http://www.dynamicdrive.com/style/"><span>CSS Examples</span></a>
<ul>
<li><a href="#">Activities 1</a></li>
<li><a href="#">Activities 2</a></li>
<li><a href="#">Activities 3</a>
<ul>
<li><a href="#">Water Sports 1</a></li>
<li><a href="#">Water Sports 1</a></li>
<li><a href="#">Water Sports 1</a></li>
<li><a href="#">Water Sports 1</a></li>
</ul>
</li>
<li><a href="#">Activities 4</a></li>
</ul>
</li>
<li><a href="http://tools.dynamicdrive.com"><span>Tools</span></a></li>
<li><a href="http://www.javascriptkit.com/"><span>JavaScript</span></a>
<ul>
<li><a href="#">Traveling 1</a></li>
<li><a href="#">Traveling 2</a></li>
<li><a href="#">Traveling 3</a></li>
<li><a href="#">Traveling 4</a>
<ul>
<li><a href="#">Africa 1</a></li>
<li><a href="#">Africa 2</a></li>
<li><a href="#">Africa 3</a></li>
<li><a href="#">Africa 4</a>
<ul>
<li><a href="#">Kenya 1</a></li>
<li><a href="#">Kenya 2</a></li>
<li><a href="#">Kenya 3</a></li>
<li><a href="#">Kenya 4</a></li>
<li><a href="#">Kenya 5</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Traveling 5</a></li>
</ul>
</li>
<li><a href="http://www.cssdrive.com"><span>Gallery</span></a></li>
</ul>
</div>
CSS文件中有這樣的:
.droplinetabs{
overflow: hidden;
border-bottom: 1px solid gray; /*underline across bottom of main tabs*/
}
.droplinetabs ul{
font: bold 11px Verdana, sans-serif;
margin: 0;
padding: 0;
width: 100%;
list-style: none;
}
.droplinetabs li{
display: inline;
margin: 0 2px 0 0;
padding: 0;
text-transform: uppercase;
}
.droplinetabs a{
float: left;
color: white;
background: #c76023 url(leftedge.gif) no-repeat left top; /*default background color of tabs, left corner image*/
margin: 0 4px 0 0;
padding: 0 0 4px 3px;
text-decoration: none;
letter-spacing: 1px;
}
.droplinetabs a:link, .droplinetabs a::visited, .droplinetabs a:active{
color: white;
}
.droplinetabs a span{
float: left;
display: block;
background: transparent url(rightedge.gif) no-repeat right top; /*right corner image*/
padding: 7px 9px 3px 6px;
cursor: pointer;
}
.droplinetabs a span{
float: none;
}
.droplinetabs a:hover{
background-color: #b05016; /*background color of tabs onMouseover*/
color: white;
}
.droplinetabs a:hover span{
background-color: transparent;
}
/* Sub level menus*/
.droplinetabs ul li ul{
position: absolute;
z-index: 100;
left: 0;
top: 0;
background: #c76023; /*sub menu background color */
visibility: hidden;
}
/* Sub level menu links style */
.droplinetabs ul li ul li a{
font: normal 13px Verdana;
padding: 6px;
padding-right: 8px;
margin: 0;
background: #c76023; /*sub menu background color */
}
.droplinetabs ul li ul li a span{
background: #c76023; /*sub menu background color */
}
.droplinetabs ul li ul li a:hover{ /*sub menu links' background color onMouseover. Add rounded edges in capable browsers */
background: #714421;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
}
而且js文件有這個
/*********************
//* jQuery Drop Line Menu- By Dynamic Drive: http://www.dynamicdrive.com/
//* Last updated: May 9th, 11'
//* Menu avaiable at DD CSS Library: http://www.dynamicdrive.com/style/
*********************/
var droplinemenu={
arrowimage: {classname: 'downarrowclass', src: 'down.gif', leftpadding: 5}, //customize down arrow image
animateduration: {over: 200, out: 100}, //duration of slide in/ out animation, in milliseconds
buildmenu:function(menuid){
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={h:$curobj.find('a:eq(0)').outerHeight()}
this.istopheader=$curobj.parents("ul").length==1? true : false
if (!this.istopheader)
$subul.css({left:0, top:this._dimensions.h})
var $innerheader=$curobj.children('a').eq(0)
$innerheader=($innerheader.children().eq(0).is('span'))? $innerheader.children().eq(0) : $innerheader //if header contains inner SPAN, use that
$innerheader.append(
'<img src="'+ droplinemenu.arrowimage.src
+'" class="' + droplinemenu.arrowimage.classname
+ '" style="border:0; padding-left: '+droplinemenu.arrowimage.leftpadding+'px" />'
)
$curobj.hover(
function(e){
var $targetul=$(this).children("ul:eq(0)")
if ($targetul.queue().length<=1) //if 1 or less queued animations
if (this.istopheader)
$targetul.css({left: $mainmenu.position().left, top: $mainmenu.position().top+this._dimensions.h})
if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
$mainmenu.find('ul').css({overflow: (this.istopheader)? 'hidden' : 'visible'})
//$targetul.dequeue().slideDown(droplinemenu.animateduration.over)
$targetul.dequeue().show()
},
function(e){
var $targetul=$(this).children("ul:eq(0)")
$targetul.dequeue().hide()
//$targetul.dequeue().slideUp(droplinemenu.animateduration.out)
}
) //end hover
}) //end $headers.each()
$mainmenu.find("ul").css({display:'none', visibility:'visible', width:$mainmenu.width()})
}) //end document.ready
}
}
我覺得可能是一種選擇,就是保持原來的項目名稱,並將其與新的
我試圖改變喜歡下懸停功能,但沒有工作比較:
$curobj.hover(
function(e){
var $targetul=$(this).children("ul:eq(0)")
if($anterior!=$targetul)
{
$anterior.dequeue().hide()
}
$anterior=$targetul
if ($targetul.queue().length<=1) //if 1 or less queued animations
if (this.istopheader)
$targetul.css({left: $mainmenu.position().left, top: $mainmenu.position().top+this._dimensions.h})
if (document.all && !window.XMLHttpRequest) //detect IE6 or less, fix issue with overflow
$mainmenu.find('ul').css({overflow: (this.istopheader)? 'hidden' : 'visible'})
//$targetul.dequeue().slideDown(droplinemenu.animateduration.over)
$targetul.dequeue().show()
},
function(e){
var $targetul=$(this).children("ul:eq(0)")
//$targetul.dequeue().hide()
//$targetul.dequeue().slideUp(droplinemenu.animateduration.out)
}
) //end hover
你能生產出[小提琴](http://jsfiddle.net/)? – 2013-07-04 17:07:54
是的,這裏是http://jsfiddle.net/yN8Nz/4/ –