需要帮助更改此 Jquery 代码以修复元素的垂直定位
我已在 jsFiddle 页面上设置了所有内容,请在此处查看: http://jsfiddle.net/ ryanjay/bq5eE/
我的问题是,当您打开 DIV(列)时,它将所有其他关闭的 div 对齐到其底部。有人可以帮助我添加一些 jquery 代码来实现它,以便当您打开每个 DIV(列)时,其他 div 保持与顶部对齐。也许这与边距顶部有关,我不确定。
我还使用了一个围绕列的滑块,因此浮动它们不是一个选项..它们只是换行到下一行。它们必须具有 inline-block 的显示。
谢谢
这是我的 HTML:
<div class="column">
<div class="open">
open
</div>
<div class="close">close</div>
<div class="contentInner">
<div class="ProjectContainer">
Content goes here.
</div>
</div>
</div>
<div class="column">
<div class="open">
open
</div>
<div class="close">close</div>
<div class="contentInner">
<div class="ProjectContainer">
Content goes here.
</div>
</div>
</div>
这是我的 Jquery:
$(document).ready(function() {
//Page Load
$('.column').css({
width: '200px',
height: '200px'
});
// Open
$('.open').click(function() {
$(this).parent().animate({
width: '400px',
height: '520px',
}, 500);
$(this).hide();
$(this).siblings('.close').show();
$(this).siblings('.contentInner').fadeIn('slow', function() {
$(this).show();
});
});
// Close
$('.close').click(function() {
$(this).parent().animate({
width: '200px',
height: '200px'
}, 500);
$(this).siblings('.contentInner').fadeOut('100', function() {
$(this).hide();
});
$(this).hide();
$(this).siblings('.open').fadeIn('150', function() {
$(this).show();
});
});
});
还有我的 CSS:
.column {
position: relative;
width: 200px;
border-left: 1px solid #999;
border-right: 1px solid #999;
height: 520px;
margin: 30px 30px 0px 0px;
display: inline-block;
text-align: left;
}
.open {
position: absolute;
margin: 0px 0px 0px 0px;
cursor: pointer;
}
.close {
position: absolute;
margin: 0px 0px 0px 368px;
cursor: pointer;
display: none;
}
.contentInner {
position: absolute;
width: 380px;
height: 400px;
font: 12px Helvetica, Arial, Sans-Serif;
font-weight: 200;
margin: 20px 0px 0px 10px;
display: none;
white-space: normal;
}
你可以随时在 jsFiddle 上看到它: http: //jsfiddle.net/ryanjay/bq5eE/
谢谢!
I have everything set up on a jsFiddle page, please take a look at it here: http://jsfiddle.net/ryanjay/bq5eE/
My problem is, when you open the DIV (column), it aligns all the other closed divs to the bottom of it. Can someone help me by adding some jquery code to make it so when you open each DIV(column) the other divs stay aligned to the top. Perhaps it has something to do with margin-top, I am unsure.
I am also using a slider that wraps around the columns, so floating them isn't an option.. they just wrap to the next line. They must have a display of inline-block.
Thanks
Here is my HTML:
<div class="column">
<div class="open">
open
</div>
<div class="close">close</div>
<div class="contentInner">
<div class="ProjectContainer">
Content goes here.
</div>
</div>
</div>
<div class="column">
<div class="open">
open
</div>
<div class="close">close</div>
<div class="contentInner">
<div class="ProjectContainer">
Content goes here.
</div>
</div>
</div>
Here is my Jquery:
$(document).ready(function() {
//Page Load
$('.column').css({
width: '200px',
height: '200px'
});
// Open
$('.open').click(function() {
$(this).parent().animate({
width: '400px',
height: '520px',
}, 500);
$(this).hide();
$(this).siblings('.close').show();
$(this).siblings('.contentInner').fadeIn('slow', function() {
$(this).show();
});
});
// Close
$('.close').click(function() {
$(this).parent().animate({
width: '200px',
height: '200px'
}, 500);
$(this).siblings('.contentInner').fadeOut('100', function() {
$(this).hide();
});
$(this).hide();
$(this).siblings('.open').fadeIn('150', function() {
$(this).show();
});
});
});
And my CSS:
.column {
position: relative;
width: 200px;
border-left: 1px solid #999;
border-right: 1px solid #999;
height: 520px;
margin: 30px 30px 0px 0px;
display: inline-block;
text-align: left;
}
.open {
position: absolute;
margin: 0px 0px 0px 0px;
cursor: pointer;
}
.close {
position: absolute;
margin: 0px 0px 0px 368px;
cursor: pointer;
display: none;
}
.contentInner {
position: absolute;
width: 380px;
height: 400px;
font: 12px Helvetica, Arial, Sans-Serif;
font-weight: 200;
margin: 20px 0px 0px 10px;
display: none;
white-space: normal;
}
You can always see it on jsFiddle here: http://jsfiddle.net/ryanjay/bq5eE/
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://jsfiddle.net/bq5eE/7/
只需向 .内容 CSS 块:
或者,如果您需要使用 jQuery 来执行此操作,请执行以下操作:
http://jsfiddle.net/bq5eE/7/
Just add a vertical-align style to the .content CSS block:
Alternately, if you need to do it with jQuery, do this: