gpt4 book ai didi

javascript - ionic 中的自动增长文本区域

转载 作者:数据小太阳 更新时间:2023-10-29 04:21:53 24 4
gpt4 key购买 nike

我正在尝试向我的应用程序添加一个自动增长的文本区域,但由于某种原因它无法正常工作。我使用的模块是 https://github.com/tagged/autogrow (在 ionic 论坛上推荐)

最佳答案

上面的答案并没有缩水——这里是一个改进的版本:

https://codepen.io/benshope/pen/xOPvpm

angular.module('app').directive('expandingTextarea', function () {
return {
restrict: 'A',
controller: function ($scope, $element, $attrs, $timeout) {
$element.css('min-height', '0');
$element.css('resize', 'none');
$element.css('overflow-y', 'hidden');
setHeight(0);
$timeout(setHeightToScrollHeight);

function setHeight(height) {
$element.css('height', height + 'px');
$element.css('max-height', height + 'px');
}

function setHeightToScrollHeight() {
setHeight(0);
var scrollHeight = angular.element($element)[0]
.scrollHeight;
if (scrollHeight !== undefined) {
setHeight(scrollHeight);
}
}

$scope.$watch(function () {
return angular.element($element)[0].value;
}, setHeightToScrollHeight);
}
};
});

这将改变你所有的文本区域来扩大/缩小。

希望对您有所帮助!

关于javascript - ionic 中的自动增长文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24480224/

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