在firefox操作系统中,根据屏幕方向调整文本区域的大小

Resize textarea with screen orientation in firefox os

本文关键字:文本 调整 区域 方向 屏幕 操作系统 firefox      更新时间:2023-09-26

我正在尝试为Firefox OS创建一个简单的文本编辑器,在该编辑器中,我使用testarea作为用户的文本字段。当我使用模拟器时,当我将屏幕方向从纵向更改为横向或横向时,我需要textarea自动更改其方向并获得全屏大小。但每次我改变方向时,我都需要重新加载应用程序:(

如果我尝试CCD_ 3,结果是未定义的。

我用来获取屏幕尺寸的波纹管代码

HTML:

<textarea id="input-text" onfocus="TextareaOnFocus()" onblur="TextareaRealeseFocus()"></textarea>

Javascript:

var textAreaSize = document.getElementById("input-text");
textAreaSize.style.height = screen.height - 74 + "px"; // -74, so that the field is not edge to edge 
textAreaSize.style.width = screen.width - 21 + "px"; // -21, so that the field is not edge to edge 

有没有办法改变键盘的大小,因为它覆盖了一半的屏幕,所以我的文本文件变得很小。

只需在CSS中设置文本区域的大小,因为我们现在有了calc和vw/vh等很酷的东西。

#input-text {
   height: calc(100vh - 74px);
   width: calc(100vw - 21px);
}

旋转时也会自动工作。


screen.orientation不起作用的原因是因为目前API方向是非标准的,所以您需要在前面加上moz。F.e.:screen.mozOrientation运行良好。