我正在用jQuery開發一個導航菜單。我來到了可以滑下第一個子菜單並向右滑動第二個子菜單的步驟。當我mouseout它會淡出。但問題是當我第二次完成鼠標移動時。它不會工作。第一次懸停它工作正常。我無法識別問題。我認爲鼠標移出功能在執行後不會停止或完全恢復。誰能給我一個建議,這個問題第二次使用jQuery導航菜單mouseover和mouseout不起作用
我的jQuery代碼
<script type="text/javascript">
$(document).ready(function() {
jQuery('.box1').mouseover(function() {
///$(".box2").stop().slideDown('slow');
$('.box2').stop().animate({
height: 50
}, 1000);
});
jQuery('.box1').mouseout(function() {
$('.box2').stop().fadeOut();
// $(".box2").stop().slideUp('slow');
});
jQuery('.box4').mouseover(function() {
// $(".box3").stop().slideDown('slow');
//$(".box3").show('slide', {direction: 'left'}, 800);
$('.box3').stop().animate({
width: 200
}, 1000);
});
jQuery('.box4').mouseout(function() {
//$(".box3").stop().slideUp('slow');
// $(".box3").hide('slide', {direction: 'left'}, 800);
$('.box3').stop().fadeOut();
});
});
</script>
我的HTML代碼
<ul >
<li class="box1" >
<div class="box_sub" >Home</div>
<ul>
<li style="float:left;" class="box4" >
<div id="box2" class="box2" style="float:left">Sub 1.0</div>
<ul style="float:left;">
<li id="box3" class="box3" style="float:left;clear:none;" > Sub Sub 1.1</li>
</ul>
</li>
</ul>
</li>
</ul>
我的CSS代碼
.box_sub {
width: 200px;
height: 50px;
background-color: #0066CC;
color: #FFF;
text-align: center;
line-height: 50px;
font: Verdana, Geneva, sans-serif;
font-size: 14px;
padding-top: 20px;
padding-bottom: 20px;
cursor: pointer;
}
.box2 {
width: 200px;
height: 0px;
background-color: #0066CC;
color: #FFF;
text-align: center;
line-height: 50px;
font: Verdana, Geneva, sans-serif;
font-size: 14px;
cursor: pointer;
}
.box3 {
width: 0px;
height: 50px;
background-color: #0066CC;
color: #FFF;
text-align: center;
line-height: 50px;
font: Verdana, Geneva, sans-serif;
font-size: 14px;
padding-top: 20px;
padding-bottom: 20px;
cursor: pointer;
}
.box1 {
min-width: 200px;
}
ul {
list-style: none;
}
ul {
margin: 0;
padding: 0;
}
li {
margin: 0;
padding: 0;
}
首先要注意的是,'淡出()'集的元素的'display'到'none'。你不會重新設置它,所以它不會再顯示。 – George
是的,嘗試在動畫之前添加'.show()'。 – Brewal