HTML - 使用命名锚点自动导航 #
好吧,我们可以像下面的代码一样在页面中命名锚点,
<!---Some HTML Code-->
<a href="#Mark_1">Mark 1</a>
<a href="#Mark_2">Mark 2</a>
<!---After some HTML Code-->
<a name="Mark_1">
<!---After some HTML Code-->
<a name="Mark_2">
这样我们就可以提供用于上下滚动页面的链接,但
我在网上多次看到,当您单击链接时,会打开一个新页面它包含许多主题,但页面滚动到所需位置。
这是如何完成
例如,在 stackoverflow 最近的活动中,当我们单击某个活动时,相关页面会打开,并且页面会滚动到该活动中的多个...这只是一个示例...我不知道不想要 stackoverflow 是如何做到的...我想要这是如何完成的或者该技术有任何名称吗
well we can have name anchors in our page like the following code
<!---Some HTML Code-->
<a href="#Mark_1">Mark 1</a>
<a href="#Mark_2">Mark 2</a>
<!---After some HTML Code-->
<a name="Mark_1">
<!---After some HTML Code-->
<a name="Mark_2">
by doing so we provide links that to scroll up and down a page and all but
I have seen several times on the net that when you click a link and a new page is opened and it contains many subjects but page is scrolled to the desired position.
HOW THAT IS DONE
for example, in stackoverflow's recent activity when we click some activity the relevant page is opened and page is scrolled to that activity out of many... this is just an example.. i don't want how stackoverflow does it... what i want how is this done or is there any name for this technique
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在任何 HTML 元素的 id 属性值后面附加一个哈希值。请参阅此示例:http://en.wikipedia.org/wiki/Html#Attributes
它直接链接到有关“属性”的部分。在本节中还描述了该技术:)
You can append a hash with following the the value of the id attribute of any HTML element. See this example: http://en.wikipedia.org/wiki/Html#Attributes
It links directly to the section about "Attributes". In this section it also discribes the technique :)
你需要
记下哈希值
you need
note the hash
它所做的正是你所说的,一个命名的锚点。所以链接看起来像这样:
注意 href 中的“#”(... 3550910#3550910),这是命名部分。带您去您想去的地方。
顺便说一句,在上面的示例中,指向命名锚点的链接应该是
注意哈希值
It's doing exactly what you're talking about, a named anchor. So the link looks something like this:
Notice the '#' in the href (... 3550910#3550910), that's the named part. Takes you right where you want to go.
Btw in your example above your link to the named anchor should be
Notice the hash
我认为你说得对,但你只需要添加目标属性。
这将在新页面中打开链接,并且应该将其放置在锚点下方。不过,我通常在 href 部分使用完整的 URL。
I think you have it right, but you just need to add the target attribute.
This will open the link in a new page and should position it down the the anchor. I normally use the full URL in the href section though.