在#profile_dropdown
容器內嵌入#profile_dropdown_content
並使用懸停事件。
的jsfiddle:http://jsfiddle.net/UsWYq/1/
JS
$(document).ready(function(){
$("#profile_dropdown").hover(function(){
clearTimeout($(this).data('timeoutId'));
$("#profile_dropdown_content").fadeIn("slow");
}, function(){
var someElement = $("#profile_dropdown");
var timeoutId = setTimeout(function(){
$("#profile_dropdown_content").fadeOut("slow");
}, 650);
//set the timeoutId, allowing us to clear this trigger if the mouse comes back over
someElement.data('timeoutId', timeoutId);
});
});
HTML
<div id="profile_dropdown">
<div class="inner">Hover Me</div>
<div id="profile_dropdown_content">Display Me</div>
</div>
<div id="profile_dropdown"></div>
CSS
個
#profile_dropdown {
background:whitesmoke;
float:left;
}
#profile_dropdown .inner {
height:100px;
width:100px;
}
#profile_dropdown_content {
display:none;
background:red;
height:100px;
width:100px;
}
選項2
你可以做的另一件事是CSS3過渡:http://jsfiddle.net/Ezxm5/
#profile_dropdown {
background:whitesmoke;
float:left;
}
#profile_dropdown:hover #profile_dropdown_content {
display:block;
opacity:1;
height:100px;
}
#profile_dropdown .inner {
height:100px;
width:100px;
}
#profile_dropdown_content {
opacity:0;
background:red;
height:0;
width:100px;
overflow:hidden;
-webkit-transition: opacity 0.4s ease-in, height 0.4s ease-out;
-moz-transition: opacity 0.4s ease-in, height 0.4s ease-out;
-ms-transition: opacity 0.4s ease-in, height 0.4s ease-out;
-o-transition: opacity 0.4s ease-in, height 0.4s ease-out;
transition: opacity 0.4s ease-in, height 0.4s ease-out;
}
我有很多想法。你可以設置一個jsfiddle來顯示問題是什麼? –
是#profile_dropdown_content #profile_dropdown的孩子嗎? –
你可以發佈你的HTML代碼嗎? – Zack