如何在TypeScript代码里获得HTML元素的css属性
生活随笔
收集整理的這篇文章主要介紹了
如何在TypeScript代码里获得HTML元素的css属性
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先從angular/core里導入ElementRef:
然后注入到構造函數中:
最后通過如下代碼訪問名為–cx-max-views的CSS屬性:
/*** Returns the maximum number of views per split-view. The number is based on the* CSS custom property `--cx-max-views`.*/protected get splitViewCount(): number {console.log('Jerry cod19: ');return Number(getComputedStyle(this.elementRef.nativeElement).getPropertyValue('--cx-max-views'));}
更多Jerry的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的如何在TypeScript代码里获得HTML元素的css属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 今年的五一“疯”了吗?网友:走不动 根本
- 下一篇: SAP Spartacus里如何查找所有