简体   繁体   English

如何使用javascript独立设置聚合物自定义元素的每个实例的光源dom

[英]how to style the light dom of each instance of a polymer custom element independently using javascript

I will like to style the light dom's css using javascript from within the custom element's definition. 我想在自定义元素的定义中使用javascript设置light dom的CSS样式。 Is it possible? 可能吗?

The premise is that I have a widget created using polymer, the content within the widget is declared in the light DOM. 前提是我有一个使用聚合物创建的小部件,该小部件中的内容在轻型DOM中声明。 I like to be able to hide widget and the logic is scripted into the custom element itself. 我希望能够隐藏小部件,并且将逻辑编写为自定义元素本身的脚本。

Using this.children , we can access the elements within the light DOM of the instance of the custom element. 使用this.children ,我们可以访问自定义元素实例的轻型DOM中的元素。 It returns the elements as an array. 它以数组形式返回元素。

In my case, I wish to set the visibility of the elements within the light DOM to hidden when the widget is being minimized. 就我而言,我希望在最小化小部件时将light DOM中的元素的可见性设置为隐藏

A for loop is used to set the visibility of all the elements within the light DOM 一个for循环用于设置light DOM中所有元素的可见性

for(var i = 0;i<this.children.length;i++)
{
    $(this.children[i]).css("visibility",'hidden');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM