如何使用完整page.js滚动到包含链接的特定部分?

时间:2014-04-17 14:32:32

标签: javascript jquery html fullpage.js

我使用精彩的fullpage.js制作单页网站。

这是基本代码:

<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>

我无法弄清楚如何在第0部分到第2部分中包含链接(即只是标准的<a href>链接)。我一直在搞乱锚,但无法让它发挥作用。

1 个答案:

答案 0 :(得分:9)

您只需使用anchors选项,然后使用普通链接:

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

链接看起来应该正常,但前缀为#

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

Live example

您的网址如下:

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

现在也可以在每个部分中使用html属性data-anchor="section1",以便为其定义锚点。例如:

<div id="fullpage">
    <div class="section" data-anchor="section1">Section 1</div>
    <div class="section" data-anchor="section2">Section 1</div>
</div>