根据另一个Div内容增加Div高度,它's的高度
Increase a Div height based on another Div content and it's height
当前js小提琴示例
我有两个分区.mainDiv和.sideDiv。当我单击单击以展开文本时,会显示FULL段落,并且此内容的高度会增加。
我想要什么:当我按下单击以展开文本时,.mainDiv高度会增加,并且.sideDiv高度也会增加到等于.main.Div高度。当再次主DIV减小时,.sideDiv的高度也减小。
jQuery有什么办法做到这一点吗?我不擅长jquery,所以我发现很难实现它,如果有人帮助我,那对我来说会很好。也为糟糕的英语感到抱歉
感谢
HTML
<div class="mainDiv">
<p class="click"> Click to expand </p>
<p class="hide">
and scrambled it to make a type specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with
desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
</p>
</div>
<div class="sideDiv">
<p>Should Expand this Div</p>
</div>
CSS
.mainDiv {
background-color:#ccc;
float:left;
width:200px;
}
.sideDiv {
background:yellow;
float:left;
width:200px;
height:auto;
}
JavaScript
$('.hide').hide();
$('.click').on('click', function () {
$('.hide').toggle();
});
是的,请尝试一下。
演示:http://jsfiddle.net/M35xJ/5/
$('.click').on('click', function () {
$('.hide').toggle();
$('.sideDiv').height($('.mainDiv').height());
});
更多详细信息:http://api.jquery.com/height/
将其添加到您的代码中
$('.hide').hide();
$('.click').on('click', function () {
$('.hide').toggle();
var x = $('.mainDiv').css('height'); // Added
$('.sideDiv').css('height', x); // Added
});
FIDDLE
我采用了这种方法,当切换完成时会调整大小。
$('.hide').hide();
$('.click').on('click', function () {
$('.hide').toggle(0,function() {
$('.sideDiv').height($('.mainDiv').height());
});
});
http://jsfiddle.net/M35xJ/7/
相关文章:
- Div 高度不会根据子控件自动扩展
- Div 高度不会在附加任何元素时增加
- 选中复选标记时增加 Div 高度
- 设置DIV高度,使文本不被水平剪切或切片
- 根据另一个Div内容增加Div高度,它's的高度
- Div高度动画会导致Div在jQuery中更改对齐方式
- 如何根据视口大小调整Div高度
- 基于滚动更改DIV高度
- IE7标准文档模式中SPAN/DIV高度不正确
- 如何将嵌套的DIV高度设置为与容器相同
- HTML CSS,引导响应DIV高度
- 溢出内容的Div高度
- 递增Div高度
- 响应式设计:Div高度没有在窗口大小调整时更新
- Javascript测量多个Div高度
- 如何找到真正的DIV高度
- jQuery容器Div高度不扩展
- 根据窗口内部高度改变Div高度
- Div高度在页面加载时输出为0
- 确定最大可能的DIV高度