Selaiman Fazli
Selaiman Fazli

Reputation: 11

Linking to a specific part of a HTML page

How do I create a link to a part of long webpage on another HTML site? My problem is, that I have 2 HTML pages in one: index.html?Site=Info.

It doesn't work when I make a "Jump link" with #. Any ideas?

Upvotes: 0

Views: 150

Answers (1)

Billy
Billy

Reputation: 2448

The fragment anchor should work if the part you're linking to has it set.animation added for effect

$(document).ready(function(){
   $(".anchor").click(function(e){
      $('html, body').animate({
       scrollTop: $($(this).attr('href')).offset().top
      }, 1000);
   });
});
#top{background-color:red;}
#middle{background-color:yellow;}
#bottom{background-color:green;}
div.block{height:400px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="toppage"></div>
<a class="anchor" href="#top"> 
        <div class="arrow-down-light-blue">top</div>
    </a>


    <a class="anchor" href="#middle">
        <div class="arrow-down-light-blue">middle</div>
   

    <a class="anchor" href="#bottom">
        <div class="arrow-down-light-blue">bottom</div>
    </a>

<div class="block" id="top">The top
  <a class="anchor" href="#toppage"> Back to top</a>
      </div>
<div class="block" id="middle">The middle
      <a class="anchor" href="#toppage"> Back to top</a>
      </div>
<div  class="block" id="bottom">The bottom
      <a class="anchor" href="#toppage"> Back to top</a>
      </div>

Upvotes: 2

Related Questions