在聚合物中创建锚元素 [英] Create Anchor Element in polymer

查看:70
本文介绍了在聚合物中创建锚元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能创建一个将用作聚合物锚点的元素.例如

Is it possible to create an element that will be used as an anchor in polymer. So for example

<template repeat="{{ content in contentitems }}">
    <div id="{{ content.id }}">{{content.stuff}}</div>
</template>

是否可以创建指向content#id锚点的超链接,例如 http://example.com/#someid

Would it be possible to create a hyperlink to the content#id anchor like http://example.com/#someid

或者,我们可以使用querySelector如下所示查询该元素,然后在必要时使用JavaScript将其滚动到视图中.我宁可不必使用JS路由器进行锚点超链接?

Alternatively, we can query that element with querySelector like the below and then scroll it into view if necessary with JavaScript. I'd rather not have to use a JS router however for anchor hyperlinking?

scrollIntoViewFunc(document.querySelector("html /deep/ #someid"))


这是我要使用的实际网址: http://megawac.github .io/status-whiskey/#status-408

推荐答案

Web组件之神(又名Blink工程师)已经决定,影子根内部的锚点不会像在主文档中那样自动滚动到视图中.出于这个原因,我相信您将必须像显示的那样执行一些操作,才能使用JavaScript进行处理.

The Web Component gods (aka Blink engineers) have decided that anchors inside of shadow-roots will not automatically scroll into view like they do in the main document. For this reason, I believe you will have to do something like you showed to handle this in JavaScript.

经过简短搜索,我在规范,它确实需要在某个地方阐明.

After brief searching, I couldn't find a reference to this question in the spec, it really needs to be spelled out somewhere.

如果您提出了通用的解决方案,请将其元素化并分享给社区. = P

If you come up with general solution, elementize it and share it back to the community. =P

这篇关于在聚合物中创建锚元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆