简体   繁体   中英

Move to a <section> when click on an <a> in the same page

I would like to know how to scroll to a <section> element on my page when cliking on an <a> element, both placed in the same page.

Thank you all in advance. Cheers.

This is a native and easier way to do this. You just have to give id to your section (or any HTML element) in the href attribute of the ancher tag.

Sample snippet:

<a href="#sectionId">GO to section</a>

<section id="sectionId">

//your code

</section>

The W3C Standard

您可以(在纯 HTML 中)按照以下问题的描述将哈希值放入锚标记中: hash in anchor tags

ScrollIt.js can help you in this regard.

http://bytemuse.com/scrollIt.js/

4 simple steps and you're done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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