Javascript 使textarea height扩展到container div';s高度(调整大小时)
有没有办法使这两个相邻浮动的文本区域始终保持相同的高度。其容器的高度,当其中一个容器调整大小时,该高度将展开。我试着把它们放在一个容器中,并将它们的高度设置为100%。我尝试使用jquery函数来调整它们的大小(你可以看到它在小提琴上被注释掉),但失败了 如何在调整大小后使它们始终保持相同的高度Javascript 使textarea height扩展到container div';s高度(调整大小时),javascript,jquery,css,textarea,Javascript,Jquery,Css,Textarea,有没有办法使这两个相邻浮动的文本区域始终保持相同的高度。其容器的高度,当其中一个容器调整大小时,该高度将展开。我试着把它们放在一个容器中,并将它们的高度设置为100%。我尝试使用jquery函数来调整它们的大小(你可以看到它在小提琴上被注释掉),但失败了 如何在调整大小后使它们始终保持相同的高度 textarea{ min-height:150px; float:left; display:inline-block; overflow:auto; } #t2{ width:
textarea{
min-height:150px;
float:left;
display:inline-block;
overflow:auto;
}
#t2{
width:30px;
overflow:hidden;
text-align: right;
white-space:nowrap;
}
div.container{
min-height:150px;
border:1px solid black;
display:inline-block;
}
这将有助于:
$(".t").mouseup(function(){
$(".t").not($(this)).css("height", parseInt($(this).css("height"),10));
});
您可以使用
mousemove
而不是mouseup
实现“实时”效果。尝试将textarea的高度设置为100%,容器的高度设置为150px。当textarea为100%时,它将自动适合您的父div的高度,希望这有帮助
textarea {
height: 100%;
width: 100%;
display: block;
}
分区集装箱{
高度:150像素;
最小高度:150px;
边框:1px纯黑;
显示:内联块;
}您可以使用javascript实现以下场景。一旦父元素更改了其维度(例如高度),则调用functios(ES6 Javascript版本):
对非常感谢你!
const makeDimensionsEqual = (someTextareaSelector, someParentElementSelector) => {
document.querySelectorAll(someTextareaSelector)[0].style.height =
document.querySelectorAll(someParentElementSelector)[0]
.getBoundingClientRect().height + "px"
}
const someTextareaSelector = '...'
const someParentElementSelector = '...'
makeDimensionsEqual(someTextareaSelector, someParentElementSelector)