如何推迟fullPage.js滚动? [英] How to defer fullPage.js scroll?

查看:79
本文介绍了如何推迟fullPage.js滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户滚动到任意位置时,我需要: 1.停止滚动 2.动画出本节中的内容 3.然后触发滚动.

When the user scrolls anywhere, I need to: 1. stop scrolling 2. animate out the stuff in section 3. trigger the scroll then.

我发现的所有内容都通过返回onLeave回调false来停止滚动.但是在这种情况下,我以后将无法触发滚动.

Everything I found is stopping scrolling by returning onLeave callback false. But in this case I can't trigger the scroll later.

new fullpage('#fullpage', {
  licenseKey: 'OPEN-SOURCE-GPLV3-LICENSE',
  sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
  
  onLeave: (origin, destination, direction) => {
    
    // This disables scroll, but eliminates all
    // the code below too. This is the only way
    // to disable scroll I found in documentation.
    return false;
    
    // Here I suppose to do my animations
    (() => {
      $('.section').text('My fancy animations! Whoa!');
    })();
    
    // And nooow I need to resume the scroll as such
    $('section *').one('webkitAnimationEnd oAnimationEnd msAnimationEnd animationend', () => {
      
      if(direction === 'down') {
        fullpage_api.moveSectionDown();
      } else {
        fullpage_api.moveSectionUp();
      }
      
    });
    

  }
});

.section {
  text-align:center;
  font-size: 3em;
}

<script src="https://rawgit.com/alvarotrigo/fullPage.js/dev/src/fullpage.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="fullpage">
    <div class="section">Section 1</div>
    <div class="section">Section 2</div>
    <div class="section">Section 3</div>
    <div class="section">Section 4</div>
</div>

推荐答案

所以我认为您在问如何将滚动延迟到某些动画完成之后.这是一个可行的示例: https://jsfiddle.net/9w1tb85p/46/您只需添加其他动画并跟踪过渡将花费多长时间.

So I think you are asking how to delay the scrolling until after some animations have complete. Here is a working example for that: https://jsfiddle.net/9w1tb85p/46/ You just need to add your additional animations and keep track of how long the transitions will take.

CSS

.section {
  text-align:center;
  font-size: 3em;
}

HTML

<script src="https://rawgit.com/alvarotrigo/fullPage.js/dev/src/fullpage.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="fullpage">
    <div class="section" id="section4">Section 1</div>
    <div class="section">Section 2</div>
    <div class="section">Section 3</div>
    <div class="section">Section 4</div>
</div>

JavaScript

Javascript

var done = false;
var animationTimeout;
var transitionTimeout;
var animationTime = 1000;
var transitionTime = 500;

new fullpage('#fullpage', {
  sectionsColor: ['yellow', 'orange', '#C0C0C0', '#ADD8E6'],
  onLeave: function(origin, destination, direction) {
        if (done) return ;
        //cancel any previous timeout as onLeave fires quite a bit.
        clearTimeout(animationTimeout);
    clearTimeout(transitionTimeout);
    // do animations
    $('.section').text('My fancy animations! Whoa!'+Math.random());
    // after animation time scroll up or down
    animationTimeout = setTimeout(()=>{      
      //deal with scroll
      done = true;
      if(direction === 'down') {
          fullpage_api.moveSectionDown();
      } else {
          fullpage_api.moveSectionUp();
      }
      transitionTimeout=setTimeout(()=>done=false,transitionTime);
    },animationTime);
    return done;    
  }
});

这篇关于如何推迟fullPage.js滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆