admin管理员组文章数量:1278853
I'm currently using polymer's core-scaffold & co. to create an header/sidebar with a content area. I'm currently having the problem that I cannot access certain properties of the content element, such as scrollTop. (since the actual scrollTop property that I need to access is defined in the shadow DOM.)
This conflicts with a lazyload jquery plugin I'm using. The plugin is checking the window.scrollTop but changing the plugin to check the scrollTop of my content (that scrolls instead of the window) won't have any affect, since the scrollTop is "hidden" in the shadow DOM.
Is there a way to access the shadow DOM elements? The only thing I've been able to find is accessing shadow DOM objects you created yourself with createShadowroot (or whatever it was called), but I can't seem to find any reference on how to access already existing/created shadow roots.
Sample code below
<core-scaffold>
<core-header-panel navigation flex mode="seamed">
<core-toolbar>
<!--fixed toolbar-->
</core-toolbar>
<core-menu theme="core-light-theme">
<core-item icon="settings" label="item1"></core-item>
<core-item icon="settings" label="item2"></core-item>
</core-menu>
</core-header-panel>
<div tool>
<!--fixed header-->
</div>
<div id="content">
<!-- get scrollTop of content? -->
</div>
</core-scaffold>
I'm currently using polymer's core-scaffold & co. to create an header/sidebar with a content area. I'm currently having the problem that I cannot access certain properties of the content element, such as scrollTop. (since the actual scrollTop property that I need to access is defined in the shadow DOM.)
This conflicts with a lazyload jquery plugin I'm using. The plugin is checking the window.scrollTop but changing the plugin to check the scrollTop of my content (that scrolls instead of the window) won't have any affect, since the scrollTop is "hidden" in the shadow DOM.
Is there a way to access the shadow DOM elements? The only thing I've been able to find is accessing shadow DOM objects you created yourself with createShadowroot (or whatever it was called), but I can't seem to find any reference on how to access already existing/created shadow roots.
Sample code below
<core-scaffold>
<core-header-panel navigation flex mode="seamed">
<core-toolbar>
<!--fixed toolbar-->
</core-toolbar>
<core-menu theme="core-light-theme">
<core-item icon="settings" label="item1"></core-item>
<core-item icon="settings" label="item2"></core-item>
</core-menu>
</core-header-panel>
<div tool>
<!--fixed header-->
</div>
<div id="content">
<!-- get scrollTop of content? -->
</div>
</core-scaffold>
Share
Improve this question
asked Jul 15, 2014 at 17:35
Andreas GalsterAndreas Galster
4156 silver badges18 bronze badges
1 Answer
Reset to default 11Every element that has ShadowDOM also has a shadowRoot
property which describes the underlying elements (as a document
).
e.g, some_element.shadowRoot.firstElementChild
You can also use querySelector
to reach in to a shadow root, for example:
document.querySelector('core-scaffold::shadow .someclass')
would find the first element with someclass
in the shadow-root of the first core-scaffold
.
本文标签: Access shadow DOM properties (polymer) with javascriptjqueryStack Overflow
版权声明:本文标题:Access shadow DOM properties (polymer) with javascriptjquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741208840a2358696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论