gpt4 book ai didi

javascript - 扩展文本框,需要边距或反页移动

转载 作者:行者123 更新时间:2023-11-28 02:49:33 26 4
gpt4 key购买 nike

我有一个扩展的文本框,效果“很好”。

我正在使用来自这个线程的代码:CSS Textarea that expands as you type text这是我正在使用的代码:

$('textarea').on('paste input', function () {
if ($(this).outerHeight() > this.scrollHeight){
$(this).height(1)
}
while ($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))){
$(this).height($(this).height() + 1)
}
});

1) 我的问题是如果有很多通信网并且文本框靠近底部...实际类型行/区域太低。它实际上位于浏览器的底部边缘。所以第一个目标是有最低类型的线/区域/光标,边缘上方约 40px。

enter image description here

2) 另一个相关的问题是,即使我滚动回输入,按下一个键的那一刻页面滚动,结果:线/光标回到最底部。

我的一个想法是扩展文本框,但将页面向上移动一行以补偿文本框的扩展。每行一行。这可能吗?

最佳答案

解决了我的问题。我完全按照我的想法做了,将窗口向下移动了一个字体行以补偿文本框的扩展。我的字体大小是 12px,所以我将窗口移动了 12px。结果代码多了 1 行:

tbxComments.on('paste input', function () {
if ($(this).outerHeight() > this.scrollHeight) {
//alert('inside');
$(this).height('64')
}
while ($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) {
$(this).height($(this).height() + 1);
**window.scrollBy(0, 12);**
}
});

我希望这对其他人有帮助!

关于javascript - 扩展文本框,需要边距或反页移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46735355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com