8

I'm using the fabulous fullpage.js to make a single page website.

Here's the basic code:

<div id="fullpage">
    <div class="section" id="section0">
        <h1>Page 0</h1>
        <p>Some text 0</p>      
    </div>
    <div class="section" id="section1">
        <h1>Page 1</h1>
        <p>Some text 1</p>      
    </div>
    <div class="section" id="section2">
        <h1>Page 2</h1>
        <p>Some text 2</p>      
    </div>
</div>

What I can't figure out is how to include a link in section 0 to section 2 (i.e. just a standard <a href> link). I've been messing around with anchors but can't get it to work.

Garry Pettet
  • 7,482
  • 22
  • 60
  • 97

1 Answers1

14

You only need to use the anchors option and then use normal links:

$('#fullpage').fullpage({
    anchors: ['section1', 'section2', 'section3', 'section4']
});

The link should look normally, but prefixed bye #:

<a href="#section3">Link to section 3</a>

Live example

Your URLs will look like:

http://yoursite.com/#section1
http://yoursite.com/#section2
http://yoursite.com/#section3
http://yoursite.com/#section4

Now it is also possible to use the html attribute data-anchor="section1" in each section in order to define the anchor for it. For example:

<div id="fullpage">
    <div class="section" data-anchor="section1">Section 1</div>
    <div class="section" data-anchor="section2">Section 1</div>
</div>
Alvaro
  • 37,936
  • 23
  • 138
  • 304
  • Perfect. I hadn't realised that the anchors property of the fullpage initialisation referenced the sections in the order that they are defined. Thanks a lot Alvaro. Great script btw. – Garry Pettet Apr 17 '14 at 16:55
  • That was helpful, however to use anchor links pointing to a particular section, one must use the anchor option while initializing fullpage.js. – Ashesh Jun 23 '15 at 17:11
  • @Ashesh as its detailed in the answer :) – Alvaro Jun 24 '15 at 09:58
  • 1
    For others: Be careful! data-anchor tags can not have the same value as any ID element on the site (or NAME element for IE). – C. Skjerdal Sep 24 '20 at 17:58