我很确定这就是你想要的,代码用我所做的注释:
演示: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");
});
});
</p>
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;
}
</p>
HTML:相同