javascript - 以编程方式垂直调整 div 的大小

标签 javascript angular css typescript

我正在使用 Angular4+。

我想以编程方式垂直调整 div 的大小。我不知道该怎么做。我不知道从哪里开始。以及如何实现它。我对使用 jquery 不感兴趣。使用 Angular 方式实现此目的的任何想法或解决方案。

.textarea {
   min-height: 150px;
   border:1px solid #ddd;
   padding:15px;
   position:relative;
}

.textarea::before{
   content: '';
   position: absolute;
   bottom: 0;
   margin-left: -15px;
   cursor: s-resize;
   height: 9px;
   width: 100%;
   border-top: 1px solid #f1f1f1;
   overflow: hidden;
   background-color: #eff0f1;
   background-image: url('https://cdn.sstatic.net/Sites/stackoverflow/img/sprites.svg');
   background-image: url('https://cdn.sstatic.net/Sites/stackoverflow/img/sprites.svg'),none;
   background-position: 210px -364px;
   background-size: initial;
   background-repeat: no-repeat;
}
<div class="textarea"contenteditable="true">
  this is a text area
</div>

堆栈 Blitz https://stackblitz.com/edit/angular-text-resizable

最佳答案

ngStyle 应该可以解决问题:

<div class="textarea"contenteditable="true" [ngStyle]="{'height.px': height}">
this is a text area
</div>

其中 height 是组件中的一个变量:

@Component(...)
export class Component {
  height = 500;
}

关于javascript - 以编程方式垂直调整 div 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46409873/

相关文章:

php - 有没有办法检测浏览器是否支持 CSS3 动画?

css - 容器 "CSS outline"的大小在 chrome/ie 和 FF 中不同

html - 渐变在 Firefox 和 IE 中不起作用

angular - workbox-webpack-plugin 和 Angular。如何在 Angular 中监听 broadcastUpdate 事件

html - 棱 Angular 分明。从 html 标记中删除属性的构建步骤

javascript - 如何在嵌套的html文件中执行脚本代码?

javascript - 从数组获取值到模态参数

javascript - PrimeNG p-table header 选择所有具有延迟加载和分页的持久性

javascript - 使用javascript选择计算税率

javascript - 加深十六进制颜色不起作用