[英]JQuery Minimize & Maximize HTML Div
Basically I am trying to make a minimize/maximize div with jquery animation. 基本上,我试图用jQuery动画制作一个最小化/最大化div。 I have a wrapper div named
leftFilterBox
. 我有一个名为
leftFilterBox
的包装div。 In leftFilterBox, there is another div to wrap all the contents named filterContent
. 在leftFilterBox中,还有另一个div来包装名为
filterContent
所有内容。 So when I minimized the window, the filterContent should be collapse and the leftFilterBox will be shifted down at the same time when filterContent is collapse with jquery animation. 因此,当我最小化窗口时,filterContent应该折叠,并且在使用jquery动画将filterContent折叠时,leftFilterBox将同时下移。 Same goes to maximize.
同样也要最大化。 Here is my html code:
这是我的html代码:
<div id='leftFilterBox'>
<div style='background: linear-gradient(#848484, #2E2E2E);color: white;line-height:2.2em;padding-left:5%;width:auto;font-weight:bold;'>Traffic Conditions
<div id='filterWindowNav'><img class='minMaxFilterBox' src='img/minimizeFilterWindow.png' onClick='minimizeFilterWindow();' />
<img class='minMaxFilterBox' src='img/maximizeFilterWindow.png' onClick='maximizeFilterWindow();' />
<img class='closeFilterBox' onclick='closeLeftFilterBox();' alt='close' src='img/closeFilterWindow.png' /></div></div><br/>
<div id='filterContent'><span class='getLiveTrafficTitle'><center>Select date</center></span><hr width='85%'></div>
</div>
And my CSS: 而我的CSS:
#filterWindowNav {
float:right;
}
.minMaxFilterBox, .closeFilterBox {
width: 28px;
height: 28px;
cursor: pointer;
}
And my JavaScript: 而我的JavaScript:
function minimizeFilterWindow() {
$('#leftFilterBox').css('height', '25px');
$('#leftFilterBox').css('top', '90%');
}
function maximizeFilterWindow() {
$('#leftFilterBox').css('height', '65%');
$('#leftFilterBox').css('top', '30%');
}
Here is my jsFiddle link: Fiddle 这是我的jsFiddle链接: Fiddle
Currently, my code is just collapsing the filterWindow by setting specific some css such as height and top. 目前,我的代码只是通过设置特定的某些CSS(例如height和top)来折叠filterWindow。 I wonder is it possible to use some jquery animation like
slideUp()
or slideDown()
for enhcnacement because I tried it, but it does not work. 我想知道是否可以使用一些jquery动画(例如
slideUp()
或slideDown()
来增强效果,因为我尝试了它,但是它不起作用。
Thanks in advance. 提前致谢。
Hmm, I couldn't get your code to work, but I organized it and added some click events to call your functions. 嗯,我无法让您的代码正常工作,但是我组织了代码并添加了一些单击事件来调用您的函数。 I also added a background color to show the maximize effect is happening as it wasn't as obvious.
我还添加了背景色来显示最大化效果正在发生,因为它并不那么明显。
Updated fiddle demo 更新了小提琴演示
$('#minimize').click(function(){
minimizeFilterWindow();
});
$('#maximize').click(function(){
maximizeFilterWindow();
});
function minimizeFilterWindow() {
$('#leftFilterBox').css('height', '25px');
$('#leftFilterBox').css('top', '90%');
}
function maximizeFilterWindow() {
$('#leftFilterBox').css('height', '65%');
$('#leftFilterBox').css('top', '30%');
$('#leftFilterBox').css('background-color', '#000');
}
And, the updated HTML 而且,更新后的HTML
<div id='leftFilterBox'>
<div style='background: linear-gradient(#848484, #2E2E2E);color: white;line-height:2.2em;padding-left:5%;width:auto;font-weight:bold;'>Traffic Conditions
<div id='filterWindowNav'>
<img id='minimize' src='img/minimizeFilterWindow.png' />
<img id='maximize' src='img/maximizeFilterWindow.png' />
<img id='close' alt='close' src='img/closeFilterWindow.png' />
</div>
</div>
<br/>
<div id='filterContent'><span class='getLiveTrafficTitle'><center>Select date</center></span>
<hr width='85%' />
</div>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.