You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在fullpage.js中跳过带有ignore类的section,滚动时不停留?

实现fullpage.js跳过指定section并快速划过的方案

嘿,我刚好处理过类似的需求,用fullpage.js自带的API就能轻松搞定!咱们一步步来实现你要的“快速划过ignore类section、不停留”的效果:

核心思路

利用fullpage的回调函数检测当前滚动到的section,一旦碰到带ignore类的,就自动触发滚动到下一个/上一个有效section,同时临时加快滚动速度模拟“划过”的感觉。

1. 初始化fullpage时配置回调逻辑

在初始化fullpage的时候,通过afterLoad回调来处理进入ignore section的情况,同时配合setScrollingSpeed临时调整滚动速度:

new fullpage('.fallpage', {
  scrollingSpeed: 700, // 正常滚动的速度(毫秒)
  afterLoad: function(origin, destination, direction) {
    // 检测当前到达的section是否带有ignore类
    if (destination.item.classList.contains('ignore')) {
      // 根据滚动方向确定目标section的索引
      let targetIndex = direction === 'down' ? destination.index + 1 : destination.index - 1;
      const totalSections = fullpage_api.getSections().length;
      
      // 确保目标索引在有效范围内,避免越界
      if (targetIndex >= 0 && targetIndex < totalSections) {
        // 临时加快滚动速度,模拟快速划过的效果
        fullpage_api.setScrollingSpeed(300);
        // fullpage的索引是从1开始的,所以要加1
        fullpage_api.moveTo(targetIndex + 1);
        // 滚动完成后恢复原来的正常速度
        setTimeout(() => {
          fullpage_api.setScrollingSpeed(700);
        }, 300);
      }
    }
  }
});

2. 优化用户体验:禁止ignore section被交互

给带ignore类的section加一点CSS,避免用户点击或手动停留在这里:

.section.ignore {
  pointer-events: none; /* 禁止鼠标交互 */
  opacity: 0.6; /* 可选:加个半透明效果提示这是过渡区域 */
}

3. 边界情况处理

上面的代码已经做了索引边界检查,比如当第一个section是ignore类时,向上滚动不会触发跳转;最后一个是ignore时,向下滚动也不会越界,你可以根据自己的实际结构调整数值。

如果想要更丝滑的划过效果,可以试着修改临时滚动速度的数值(比如200-400之间),找到最适合你页面的节奏。

内容的提问来源于stack exchange,提问作者user8690699

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:24:50