我有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