我有3個div。當您點擊divChaptersHide(div1)上的「HIDE」時,它將被隱藏以顯示具有較小寬度的另一個div(divChaptersExpand)。當你在divChaptersExpand上點擊「EXPAND」時,它隱藏該div,然後再次顯示divChaptersHide。你也可以用div 3(divPowerPointExpand)完成所有這些。我遇到的問題是,當div 1(或div 3)中的文本被點擊時,我需要div 2來拉伸可用空間的整個寬度。謝謝您的幫助!當div被隱藏時增加div的寬度以佔用可用空間
HTML
<div style="margin:0 auto">
<!--CHAPTERS DIV-->
<div id="divChaptersHide" style="width:20%;background:black;color:white;float:left;height:300px;">
<div style="padding:0 10px"><p id="chaptersHideText" style="text-align:right">HIDE</p></div>
</div>
<!--POWERPOINT EXPAND DIV-->
<div id="divChaptersExpand" style="display:none;width:100px;background:black;color:white;float:left;height:300px;">
<p id="chaptersExpandText" >EXPAND</p>
</div>
<!--VIDEO DIV-->
<div id="divMainVideo" style="width:60%;background:purple;color:white;float:left;height:300px"></div>
<!--POWERPOINT DIV-->
<div id="divPowerPointHide" style="width:20%;background:black;color:white;float:right;height:300px">
<div style="padding:0 10px"><p id="powerPointHideText" style="text-align:left"><a>HIDE</a></p></div>
</div>
<!--POWERPOINT EXPAND DIV-->
<div id="divPowerPointExpand" style="display:none;width:100px;background:black;color:white;float:right;height:300px;">
<p id="powerPointExpandText" >EXPAND</p>
</div>
jQuery的
$(function(){
chaptersHide();
powerPointHide();
expandChapters();
expandPowerPoint();
});
function chaptersHide(){
$("#chaptersHideText").click(function(){
$("#divChaptersHide").hide("scale", {percent:0, origin: 'top'}, 500);
setTimeout(function(){$('#divChaptersExpand').show("drop",{direction:'left'},500)}, 500);
});
}
function powerPointHide(){
$("#powerPointHideText").click(function(){
$("#divPowerPointHide").hide("scale", {percent:0, origin: 'top'}, 500)
setTimeout(function(){$('#divPowerPointExpand').show("drop",{direction: 'right'},500)},500);
});
}
function expandChapters(){
$('#chaptersExpandText').click(function(){
$('#divChaptersExpand').hide("drop", { direction: "left" }, 500);
setTimeout(function(){$('#divChaptersHide').show("scale", {origin:'top'}, 500)},500);
});
}
function expandPowerPoint(){
$('#powerPointExpandText').click(function(){
$('#divPowerPointExpand').hide("drop", { direction: "right" }, 500);
setTimeout(function(){$('#divPowerPointHide').show("scale", {origin:'top'}, 500)},500);
});
}
非常感謝您的幫助。當主div伸展以填充空間時,是否有一種方法可以使它動起來,所以它不那麼生澀?另外,當你隱藏兩個div,然後顯示左邊的那個時,它會將第一個div下面的其他2個div壓下,直到它完成它的動畫,然後所有東西都跳回原位。任何想法如何解決這個問題? – ComatoseDuck 2012-02-02 21:59:03
我建議完全刪除你的setTimeout()函數,並在hide()和show()上使用回調函數。你試圖做的事情與時間有關。我會用一些代碼更新我的帖子,以便很快支持:)請務必提高我的答案! – 2012-02-03 15:02:18
輝煌。我添加了'$('#divPowerPointExpand')。stop()。hide(....'expandPowerPoint()和expandChapters()來阻止div被推到另一行,如果在完成動畫之前點擊EXPAND。非常感謝您的幫助! – ComatoseDuck 2012-02-03 20:52:00