最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Check if it is last section fullPage.js - Stack Overflow

programmeradmin6浏览0评论

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.
发布评论

评论列表(0)

  1. 暂无评论