我敢肯定這是你想要的,代碼註釋與我所做的:
演示:http://jsfiddle.net/SO_AMK/jhYWk/
的jQuery:
jQuery(document).ready(function() {
jQuery("div#toppanel").attr('tabindex', -1); //Let the DIV have focus
jQuery("div#toppanel").blur(function(){
jQuery("div#panel").animate({height: "0px"}, "fast"); // On blur, hide it
});
timerRunning = false;
jQuery("div#panel").hover(function(){ //on mouse over clear a timeout if it exists
if (timerRunning) {
clearTimeout(hoverTimeout);
timerRunning = false;
}
},
function(){ //on mouse out set the timeout
hoverTimeout = setTimeout(function(){
jQuery("div#panel").animate({height: "0px"}, "fast");
}, 2000);
timerRunning = true;
});
jQuery('#toppanel').click(function(event){
event.stopPropagation();
});
jQuery("div.panel_button").click(function(){
jQuery("div#panel").focus().animate({ height: "250px" }, "fast");
jQuery("div.panel_button").toggle()
});
jQuery("div#hide_button").click(function(){
jQuery("div#panel").animate({height: "0px"}, "fast");
});
});
CSS :
#toppanel {
outline: 0; /* Remove yellow outline in Chrome */
z-index: 25;
text-align: center;
position: absolute;
top: 0px;
left: 0px;
}
#panel {
position: relative;
height: 0px;
margin-left: auto;
margin-right: auto;
z-index: 10;
overflow: hidden;
text-align: left;
height: 0px;
display: block;
background-color: #efefef;
border: 1px solid #000;
width: 150px;
}
#panel_contents {
height: 100%;
width: 603px;
position: absolute;
z-index: -1;
}
.the_content {
margin-top:40px;
}
HTML:同
看起來正是我想要的。謝謝! – tr3online 2012-08-03 18:20:16
看起來,按鈕向下/向上狀態仍然存在一些問題,根據你做什麼以及你做什麼,這個菜單很快就會彈出來。 – tr3online 2012-08-03 18:21:31
沒問題,但是,到目前爲止我在代碼中發現了兩個錯誤所以你應該檢查它。附:您不需要在jQuery定義的函數中使用'jQuery',即使您有另一個使用它的庫,您也可以照常使用'$'。 – 2012-08-03 18:21:54