2016-04-08 267 views
1

我已经设置了fullpage.js,但希望能够滚动到一个部分的功能,并且如果满足某些条件以在下一个滚动的相同部分内显示新的元素。这下一个滚动不应该继续下一部分。Fullpage.js - 防止滚动

使用回调函数,我已经能够确定一个部分何时需要第二次滚动。从文档中,我甚至可以在滚动发生之前取消滚动,因此可以显示新的元素而不必转到下一节。问题是让它在此之后转移到下一节。我要么停止滚动,要么再也不能滚动,或者滚动到下一部分时出现文本,因为任何一种标志都可以改变,并且在下一次滚动时会多次触发,因此它会从部分移开。

 //HTML - typical fullpage.js section 

     <div class="section"> 
      <div> 
       <h1>Default Text</h1> 
       <p class="hidden-text">Additonal text to appear on second scroll</p> 
      </div> 
     </div> 
     <div class="section"> 
      <div> 
       <h1>Next Section</h1> 
      </div> 
     </div> 

     //fullpage.js - the callbacks being used 

     afterLoad: function(anchorLink, index){ 
      preventScroll = false; 
      if(this.has(".hidden-text").length){ 
       preventScroll = true; 
      } 
     }, 
     onLeave: function(index, nextIndex, direction){ 
      if (preventScroll && direction == "down") { 
       this.find('.hidden-text').addClass('animate-text'); 
       this.find('.hidden-text').removeClass('hidden-text'); 
       return false; 
      } 
     }, 

Codepen在这里找到:http://codepen.io/anon/pen/oxEexY

+0

在jsfiddle或codepen中添加复制为我们更好地地了解您的问题。 – Alvaro

+0

刚刚添加了一个codepen。 – chrism10

回答

1

您必须添加逻辑,知道什么时候隐藏的文本已被证明。添加一个timeOut或其他东西。当发生这种情况时,将标志preventScroll更改为true

在这种情况下,我假设文本后1秒(1000毫秒)所示:

Reproduction online

另外,请注意我如何使用的$(this)而不是this