
<polymer-element name="his-elem"> <div> blah </div></polymer-element>@CustomTag('his-elem')class blah extends polymerElement { @overrIDe voID attached() { // how do I get the <his-elem>'s wIDth (just wIDth,no padding border stuff) here? // document.querySelector('his-elem').getComputedStyle().wIDth gives me "auto"... }} 更新
添加:host {display:block;}到他的元素,然后你可以通过< his-elem> .clIEntWIDth获得实际的宽度.
解决方法 当其他方法不起作用时我使用它:this.getBoundingClIEntRect().wIDth
另见https://developer.mozilla.org/en-US/docs/Web/API/Element.getBoundingClientRect
**在聚合物中<= 0.16 你需要先调用super.attached()
@overrIDe voID attached() { super.attached(); print(this.getBoundingClIEntRect().wIDth); // or print(this.getComputedStyle().wIDth); } 在调用super.attached()之前,元素尚未附加到DOM,并且不会返回适当的宽度.实际上,覆盖附加并且不会在方法中调用super.attached()来阻止附加.
总结以上是内存溢出为你收集整理的获取使用dart创建的自定义元素的宽度?全部内容,希望文章能够帮你解决获取使用dart创建的自定义元素的宽度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)