admin管理员组

文章数量:1326314

Im using fullpage plugin in my website, this is my markup

<div id="fullpage">
  <div class="section section1">Some section</div>
  <div class="section section2">Some section</div>
  <div class="section section3">Some section</div>
  <div class="section section4">Last section</div>
</div>

In my website I want to do the following: User will scroll down section per section, when user reaches the last section I want to redirect the user to another page, how can I check that user is in last section in fullpage.js?

Im using fullpage plugin in my website, this is my markup

<div id="fullpage">
  <div class="section section1">Some section</div>
  <div class="section section2">Some section</div>
  <div class="section section3">Some section</div>
  <div class="section section4">Last section</div>
</div>

In my website I want to do the following: User will scroll down section per section, when user reaches the last section I want to redirect the user to another page, how can I check that user is in last section in fullpage.js?

Share Improve this question asked Aug 18, 2015 at 2:55 svelandiagsvelandiag 4,3201 gold badge42 silver badges80 bronze badges 1
  • 2 probably use .afterLoad(anchorLink, index) callback, and check if this received index parameter is equal to the length of $('#fullpage .section').length. – Tahir Ahmed Commented Aug 18, 2015 at 3:02
Add a ment  | 

2 Answers 2

Reset to default 5

You can use the afterLoad function in fullpage to achieve this. The following code snippet should give you an idea of how you can use afterLoad to check if the user is on the last section and do a redirect if so:

$('#fullpage').fullpage({
        ...

        afterLoad: function(anchorLink, index){
            // Section indexes in fullpage start at 1
            if(index === $('#fullpage .section').length){
                window.location.href = "http://stackoverflow.";
            }
        }

        ...
    });

Hi I finally figured out, I checked the fullpage has some callbacks, so I used the onLeave callback, here is my code (in CoffeeScript)

$('#fullpage').fullpage
        onLeave: (index, nextIndex, direction) ->

            if index is 3 && direction is'down'
                #redirect the user to a new page.

本文标签: javascriptCheck if it is last section fullPagejsStack Overflow