简体   繁体   English

根据窗口大小调整文本区域的大小

[英]re-size text area based on window size

I have maximize button in pop window, and i have a text area and want to re-size it based on maximizing the window. 我在弹出窗口中有最大化按钮,并且我有一个文本区域,并希望基于最大化窗口来调整其大小。 below are the code for opening the pop up window 以下是打开弹出窗口的代码

var url = "mypopup.do" + params;
var modalprops = "height=310px,width=400px,scrollbars=yes,status=no,menubar=no,resizable=yes";
window.open(url, 'winName', modalprops, false);

Give it a percentage relative width as such: 给它一个相对宽度百分比,如下所示:

<textarea style="width:100%"></textarea>

This should resize it without javascript when the browser is resized. 调整浏览器大小时,应在不使用javascript的情况下调整其大小。

EDIT : Both Width and Height are edited if you set them on your textarea's css: 编辑 :如果在textarea的CSS上设置宽度高度 ,则将同时编辑它们:

<div style="width:40%;height:40%">
    <textarea style="width:100%; height:100%;"></textarea>
</div>

This would resize the textarea accordingly, inside the div and the underlying popup window. 这将相应地在div和基础弹出窗口内调整文本区域的大小。

jsBin : http://jsbin.com/odukur/1/ jsBinhttp : //jsbin.com/odukur/1/

如果您需要微调HanletEscaño的方法(很棒),并且可以使用jQuery,我建议按照此处概述的常规方法使用resize()函数来获取窗口的大小并调整高度和您的textarea宽度。

Do you mean it ? 你是真的吗

<div>
    <textarea id='debug'></textarea>
    <button>Resize</button>
    <textarea id='test'>some words</textarea>
</div>

Jquery jQuery的

 $("button").click(function () {
    var viewportWidth = $(window).width() - 50; // -50 only want to show beacutiful >3
    var viewportHeight = $(window).height() - 90;
    $('#test').height(viewportHeight);
    $('#test').width(viewportWidth);
    $('#debug').text(viewportWidth + ':' + viewportHeight);
});

Change the 'Result' window, and click the button, you will find the textarea has been resized. 更改“结果”窗口,然后单击按钮,您将发现文本区域已调整大小。

The code is simple, I think it may inspire you. 代码很简单,我认为它可能会启发您。

Thanks Moch Daear's tips. 感谢Moch Daear的提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM