Angularjs 向上调整大小的可调整大小的文本区域(无Jquery)
我需要使Html文本区域输入自动调整在向上方向的内容增加。看看这个自动调整文本区域大小的相反方向Angularjs 向上调整大小的可调整大小的文本区域(无Jquery),angularjs,textarea,Angularjs,Textarea,我需要使Html文本区域输入自动调整在向上方向的内容增加。看看这个自动调整文本区域大小的相反方向 <!DOCTYPE html> <html> <head> <title>autoresizing textarea</title> <style type="text/css"> textarea { border: 0 none white; overflow: hidden; p
<!DOCTYPE html>
<html>
<head>
<title>autoresizing textarea</title>
<style type="text/css">
textarea {
border: 0 none white;
overflow: hidden;
padding: 0;
outline: none;
background-color: #D0D0D0;
resize: none;
}
</style>
<script type="text/javascript">
var observe;
if (window.attachEvent) {
observe = function (element, event, handler) {
element.attachEvent('on'+event, handler);
};
}
else {
observe = function (element, event, handler) {
element.addEventListener(event, handler, false);
};
}
function init () {
var text = document.getElementById('text');
function resize () {
text.style.height = 'auto';
text.style.height = text.scrollHeight+'px';
}
/* 0-timeout to get the already changed text */
function delayedResize () {
window.setTimeout(resize, 0);
}
observe(text, 'change', resize);
observe(text, 'cut', delayedResize);
observe(text, 'paste', delayedResize);
observe(text, 'drop', delayedResize);
observe(text, 'keydown', delayedResize);
text.focus();
text.select();
resize();
}
</script>
</head>
<body onload="init();">
<textarea rows="1" style="height:1em;" id="text"></textarea>
</body>
</html>
有什么建议可以帮你完成吗
PS:不能使用Jquery。如果需要,可以使用Angularjs。我对您试图做的事情有点困惑。我假设文本区域会有一些空间扩展到它上面?如果是这样的话,那就很容易了。不需要脚本 将文本区域放在div中,并为其指定以下css,例如:
height: 200px;
vertical-align: bottom;
display: table-cell;
我对你想做什么有点困惑。我假设文本区域会有一些空间扩展到它上面?如果是这样的话,那就很容易了。不需要脚本 将文本区域放在div中,并为其指定以下css,例如:
height: 200px;
vertical-align: bottom;
display: table-cell;
实际上,自动调整大小的方向取决于元素的位置 我通过对textarea元素使用简单的css实现了这一点:
position: absolute;
bottom: 0;
top: auto;
max-height: 150px;
overflow: auto;
最大高度限制了该框的增长速度超过150px,溢出:自动使其可滚动
实际上,自动调整大小的方向取决于元素的位置 我通过对textarea元素使用简单的css实现了这一点:
position: absolute;
bottom: 0;
top: auto;
max-height: 150px;
overflow: auto;
最大高度限制了该框的增长速度超过150px,溢出:自动使其可滚动
谢谢,这是必需的。谢谢,这是必需的。