How to navigate to a section of a page

后端 未结 7 1451
执念已碎
执念已碎 2020-12-01 11:04

I have a landing page with links. How can I direct user to a section of a different page?

Main Page:

Sushi


        
相关标签:
7条回答
  • 2020-12-01 11:06

    Main page

    <a href="/sample.htm#page1">page1</a>
    <a href="/sample.htm#page2">page2</a>
    

    sample pages

    <div id='page1'><a name="page1"></a></div>
    <div id='page2'><a name="page2"></a></div>
    
    0 讨论(0)
  • 2020-12-01 11:08

    Use hypertext reference and the ID tag,

    Target Text Title

    Some paragraph text

    Target Text

    <h1><a href="#target">Target Text Title</a></h1>
    <p id="target">Target Text</p>
    
    0 讨论(0)
  • 2020-12-01 11:18

    Use anchors.

    Main Page:

    <a href="/sample#sushi">Sushi</a>
    <a href="/sample#bBQ">BBQ</a>
    

    Sample Page:

    <div id='sushi'><a name="sushi"></a></div>
    <div id='bbq'><a name="bbq"></a></div>
    
    0 讨论(0)
  • 2020-12-01 11:21

    Use an call thru section, it works

    <div id="content">
         <section id="home">
                   ...
         </section>
    

    Call the above the thru

     <a href="#home">page1</a>
    

    Scrolling needs jquery paste this.. on above to ending body closing tag..

    <script>
      $(function() {
          $('a[href*=#]:not([href=#])').click(function() {
              if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
                  var target = $(this.hash);
                  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
                  if (target.length) {
                      $('html,body').animate({
                          scrollTop: target.offset().top
                      }, 1000);
                      return false;
                  }
              }
          });
      });
    </script>
    
    0 讨论(0)
  • 2020-12-01 11:22

    Use HTML's anchors:

    Main Page:

    <a href="sample.html#sushi">Sushi</a>
    <a href="sample.html#bbq">BBQ</a>
    

    Sample Page:

    <div id='sushi'><a name='sushi'></a></div>
    <div id='bbq'><a name='bbq'></a></div>
    
    0 讨论(0)
  • 2020-12-01 11:27

    Wrap your div with

    <a name="sushi">
      <div id="sushi">
      </div>
    </a>
    

    and link to it by

    <a href="#sushi">Sushi</a>
    
    0 讨论(0)
提交回复
热议问题