我不知道如何很好地解释它,但是我正在尝试构建一个文本自动扩展的文本区域,但是我发现的所有示例,文本区域都向下增长,我希望文本区域向上增长
示例:
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();
}
textarea {
border: 0 none white;
overflow: hidden;
padding: 0;
outline: none;
background-color: #D0D0D0;
resize: none;
}
<body onload="init();">
<textarea rows="1" style="height:1em;" id="text"></textarea>
</body>
http://jsfiddle.net/0a9u7h2g/2/
如何更改此代码以实现此目的?
答案 0 :(得分:2)
我假设您是说它应该向上增长,而不是向下增长。通过将MainClass
放在其包含元素的底部,它将被迫向上增长。
class SuperClass(MainClass):
def __init__(self):
super().__init__()
self._index = 0
@property
def index(self):
return self._index
@index.setter
def index(self, value):
self._index = value
textarea
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();
}