Vue FullPage.js 完整使用指南:Vue 3 官方全屏滚动解决方案

概述

vue-fullpage.js 是 FullPage.js 的官方 Vue.js 3 包装器,为 Vue 3 应用提供了强大的全屏滚动功能。该插件基于成熟的 FullPage.js 库,支持多种滚动效果和丰富的配置选项,特别适用于企业级数据大屏、产品展示、单页应用等场景。

官方信息:

  • GitHub 仓库:alvarotrigo/vue-fullpage.js

适用场景:

  • 企业数据可视化大屏
  • 领导驾驶舱系统
  • 产品功能演示页面
  • 企业官网首页
  • 多媒体展示应用

🚀 安装与配置

1. 安装依赖

# 使用 npm
npm install --save vue-fullpage.js# 使用 yarn
yarn add vue-fullpage.js# 使用 pnpm
pnpm add vue-fullpage.js

2. 在 main.ts 中全局注册

import { createApp } from 'vue'
import App from './App.vue'
import VueFullPage from 'vue-fullpage.js'
import 'vue-fullpage.js/dist/style.css'const app = createApp(App)
app.use(VueFullPage)
app.mount('#app')

基础使用

1. 基本结构

根据官方文档,vue-fullpage.js 创建了一个 <full-page> 组件:

<template><div><full-page ref="fullpage" :options="options" id="fullpage"><!-- 第一屏 --><div class="section"><div class="screen-content"><h1>第一屏内容</h1></div></div><!-- 第二屏 --><div class="section"><div class="screen-content"><h1>第二屏内容</h1></div></div><!-- 第三屏 --><div class="section"><div class="screen-content"><h1>第三屏内容</h1></div></div></full-page></div>
</template><script setup lang="ts">
import { ref } from 'vue'// fullpage 引用
const fullpage = ref<any>(null)// 配置选项 - 支持所有 FullPage.js 选项
const options = ref({// 许可证(商业使用必需)licenseKey: 'YOUR_KEY_HERE', // 替换为您的许可证密钥// 基础配置navigation: true,           // 显示导航点navigationPosition: 'right', // 导航点位置scrollingSpeed: 1000,       // 滚动速度(毫秒)easingcss3: 'ease-in-out',  // CSS3 缓动函数// 控制选项keyboardScrolling: true,    // 键盘控制touchSensitivity: 5,        // 触摸灵敏度autoScrolling: true,        // 自动滚动fitToSection: true,         // 适配屏幕// 回调函数afterLoad: (origin: any, destination: any) => {console.log('切换到屏幕:', destination.index + 1)},onLeave: (origin: any, destination: any) => {console.log('离开屏幕:', origin.index + 1, '前往:', destination.index + 1)}
})
</script><style scoped>
/* 确保 fullpage 容器占满整个视口 */
:deep(#fullpage) {position: fixed;top: 0;left: 0;width: 100%;height: 100vh;z-index: 1;
}/* 确保 section 占满整个高度 */
:deep(.fp-section) {height: 100vh !important;
}.screen-content {width: 100%;height: 100%;display: flex;flex-direction: column;justify-content: center;align-items: center;padding: 24px;box-sizing: border-box;
}
</style>

高级功能

1. 自定义导航菜单

<template><!-- 自定义导航菜单 --><div class="top-nav-menu"><div class="nav-item" :class="{ active: currentSection === 0 }" @click="goToSection(0)"><div class="nav-icon">🏠</div><div class="nav-text">首页</div></div><div class="nav-item" :class="{ active: currentSection === 1 }" @click="goToSection(1)"><div class="nav-icon">📊</div><div class="nav-text">数据</div></div><div class="nav-item" :class="{ active: currentSection === 2 }" @click="goToSection(2)"><div class="nav-icon">⚙️</div><div class="nav-text">设置</div></div></div><full-page ref="fullpage" :options="options" id="fullpage"><!-- 屏幕内容 --></full-page>
</template><script setup lang="ts">
import { ref } from 'vue'const fullpage = ref<any>(null)
const currentSection = ref(0)// 菜单点击处理函数
const goToSection = (sectionIndex: number) => {if (fullpage.value && fullpage.value.api) {fullpage.value.api.moveTo(sectionIndex + 1)}
}const options = ref({navigation: false, // 隐藏默认导航点afterLoad: (_origin: any, destination: any) => {currentSection.value = destination.index}
})
</script><style scoped>
.top-nav-menu {position: fixed;top: 20px;left: 20px;z-index: 1000;display: flex;gap: 8px;background: rgba(255, 255, 255, 0.95);backdrop-filter: blur(10px);border-radius: 12px;padding: 12px 16px;box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}.nav-item {display: flex;align-items: center;gap: 8px;padding: 10px 14px;border-radius: 8px;cursor: pointer;transition: all 0.3s ease;color: #606266;
}.nav-item:hover {background: rgba(64, 158, 255, 0.1);color: #409eff;
}.nav-item.active {background: linear-gradient(135deg, #409eff, #66b3ff);color: white;
}
</style>

解决滚动重定向问题

在使用 Vue FullPage.js 时,可能会遇到以下问题:

  1. 页面滚动被 Vue Router 的 scrollBehavior 重定向
  2. 浏览器默认滚动行为与 FullPage.js 冲突
  3. 移动端触摸滚动事件干扰

解决方案

1. 路由配置优化
// router/index.ts
import { createRouter, createWebHistory, type RouterScrollBehavior } from 'vue-router'const router = createRouter({history: createWebHistory(),routes: [{path: '/dashboard',name: 'leadershipDashboard',component: () => import('@/views/LeadershipDashboard/LeadershipDashboard.vue'),meta: { disableScroll: true, // 标记需要禁用滚动的页面fullPage: true }}],scrollBehavior: ((to, from, savedPosition) => {// 如果目标页面需要禁用滚动,返回 falseif (to.meta.disableScroll) {return false}// 如果是从全屏页面跳转,重置滚动位置if (from.meta.fullPage) {return { top: 0, left: 0 }}// 其他情况保持默认行为if (savedPosition) {return savedPosition}return { top: 0, left: 0 }}) as RouterScrollBehavior
})export default router

隐藏 右下角 水印

1. CSS 方式隐藏水印
/* 在全局样式文件或组件样式中添加 */
/* 隐藏 fullPage.js 水印 - 方法一:通用选择器 */
.fp-watermark,
.fp-watermark a,
[data-watermark],
.fp-watermark-text,
div[style*="position: fixed"][style*="bottom: 0"][style*="right: 0"] {display: none !important;visibility: hidden !important;opacity: 0 !important;
}/* 方法二:更精确的选择器 */
div[style*="position: fixed"][style*="bottom: 0"][style*="right: 0"][style*="z-index: 999999"] {display: none !important;visibility: hidden !important;opacity: 0 !important;
}/* 方法三:针对特定类名 */
.fp-watermark,
.fp-watermark a,
.fp-watermark-text {display: none !important;visibility: hidden !important;opacity: 0 !important;pointer-events: none !important;
}

常见问题与解决方案

1. 图表不显示问题

问题描述: ECharts 图表在全屏滚动页面中无法正常显示。

解决方案:

// 延迟初始化图表,确保 DOM 元素已渲染
onMounted(() => {// 使用 nextTick 确保 DOM 更新完成nextTick(() => {setTimeout(() => {initChart()}, 100)})
})// 或者使用 ResizeObserver 监听容器大小变化
const initChartWithObserver = () => {if (!chartRef.value) returnconst resizeObserver = new ResizeObserver(() => {if (chart.value) {chart.value.resize()}})resizeObserver.observe(chartRef.value)
}

2. 导航菜单层级问题

问题描述: 自定义导航菜单被 FullPage.js 容器遮挡。

解决方案:

/* 确保导航菜单在最上层 */
.top-nav-menu {position: fixed !important;top: 20px !important;left: 20px !important;z-index: 9999 !important; /* 高于 FullPage.js 的 z-index */background: rgba(255, 255, 255, 0.95) !important;backdrop-filter: blur(10px) !important;
}/* 确保 FullPage.js 容器不会覆盖导航 */
:deep(#fullpage) {z-index: 1 !important;
}

3. 移动端触摸滚动问题

问题描述: 移动端触摸滚动与 FullPage.js 冲突。

解决方案:

// 移动端触摸事件处理
const handleTouchStart = (e: TouchEvent) => {// 记录触摸开始位置touchStartY = e.touches[0].clientY
}const handleTouchMove = (e: TouchEvent) => {// 防止默认滚动行为e.preventDefault()
}// 在组件中添加触摸事件监听
onMounted(() => {document.addEventListener('touchstart', handleTouchStart, { passive: true })document.addEventListener('touchmove', handleTouchMove, { passive: false })
})

4. 内存泄漏问题

问题描述: 组件销毁后 FullPage.js 实例未正确清理。

解决方案:

onBeforeUnmount(() => {// 1. 移除事件监听器window.removeEventListener('resize', handleResize)document.removeEventListener('wheel', preventScroll)document.removeEventListener('touchmove', preventScroll)// 2. 销毁 FullPage.js 实例if (fullpage.value && fullpage.value.api) {fullpage.value.api.destroy('all')}// 3. 清理图表实例if (chart.value) {chart.value.dispose()}// 4. 清理观察器if (watermarkObserver) {watermarkObserver.disconnect()}
})

5. 性能优化问题

问题描述: 大量数据或复杂图表导致页面卡顿。

解决方案:

// 使用虚拟滚动或分页加载
const useVirtualScroll = () => {const visibleItems = ref(10)const itemHeight = 50const getVisibleData = (data: any[]) => {return data.slice(0, visibleItems.value)}const loadMore = () => {visibleItems.value += 10}return { visibleItems, getVisibleData, loadMore }
}// 图表懒加载
const useLazyChart = () => {const isChartVisible = ref(false)const observer = new IntersectionObserver((entries) => {entries.forEach(entry => {if (entry.isIntersecting) {isChartVisible.value = trueobserver.disconnect()}})})return { isChartVisible, observer }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/96647.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/96647.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

软件工程实践一:Git 使用教程(含分支与 Gitee)

文章目录目标一、快速上手1. Windows 安装 Git2. 初始化 / 克隆二、核心概念速览三、常用命令清单1) 查看状态与差异2) 添加与提交3) 历史与回溯4) 撤销与恢复&#xff08;Git 2.23 推荐新命令&#xff09;5) 忽略文件四、分支与合并&#xff08;Branch & Merge&#xff09…

css`min()` 、`max()`、 `clamp()`

min() 用来计算多个数值中最小的那个&#xff0c;非常适合做自适应。 width: min(50vw, 500px) 50vw 表示 视口宽度的 50% 500px 表示 500px min(50vw, 500px) 表示会取两者中 最小的那个 作为最终的宽度&#xff0c;。 使用场景 限制某个元素宽度不超过某个值&#xff1b; 响…

【WRF-VPRM 预处理器】HEG 安装(服务器)-MRT工具替代

目录 HEG 安装 验证 HEG 安装与否 设置环境变量(建议) 命令行接口(Command Line Interface) hegtool 工具 hegtool 用法 Header File 格式 功能1:`gdtif` 工具 – MISR 数据处理 `gdtif` 使用方式 参数文件格式(Parameter File Format) 功能2:`resample` 工具 – 重采样…

PyTorch 神经网络

神经网络是一种模仿人脑神经元链接的计算模型&#xff0c; 由多层节点组成&#xff0c; 用于学习数据之间的复杂模式和关系。神经网络通过调整神经元之间的连接权重来优化预测结果&#xff0c;这个过程可以涉及到向前传播&#xff0c;损失计算&#xff0c;反向传播和参数更新。…

详细解析苹果iOS应用上架到App Store的完整步骤与指南

&#x1f4f1;苹果商店上架全流程详解 &#x1f469;‍&#x1f4bb;想要将你的App上架到苹果商店&#xff1f;跟随这份指南&#xff0c;一步步操作吧&#xff01; 1️⃣ 申请开发者账号&#xff1a;访问苹果开发者网站&#xff0c;注册并支付99美元年费&#xff0c;获取开发者…

三维GIS开发实战!Cesium + CZML 实现火箭飞行与分离的 3D 动态模拟

CZML是一种基于JSON的数据格式&#xff0c;专门用于在Cesium中描述3D场景和时间动态数据。本文将详细介绍了CZML的特点&#xff08;JSON格式、时间动态性、层次结构等&#xff09;和基本组件&#xff0c;并给出了一个火箭发射的实例。通过搭建Cesium开发环境&#xff08;使用vi…

Spring Boot 深入剖析:BootstrapRegistry 与 BeanDefinitionRegistry 的对比

在 Spring Boot 的启动过程中&#xff0c;BootstrapRegistry 和 BeanDefinitionRegistry 是两个名为“Registry”却扮演着截然不同角色的核心接口。理解它们的差异是深入掌握 Spring Boot 启动机制和进行高级定制开发的关键。BootstrapRegistry public static ConfigurableAppl…

贪心算法应用:速率单调调度(RMS)问题详解

Java中的贪心算法应用&#xff1a;速率单调调度(RMS)问题详解 1. 速率单调调度(RMS)概述 速率单调调度(Rate Monotonic Scheduling, RMS)是一种广泛应用于实时系统中的静态优先级调度算法&#xff0c;属于贪心算法在任务调度领域的经典应用。 1.1 基本概念 RMS基于以下原则&…

Cesium4--地形(OSGB到3DTiles)

1 OSBG OSGB&#xff08;OpenSceneGraph Binary&#xff09;是基于 OpenSceneGraph&#xff08;OSG&#xff09; 三维渲染引擎的二进制三维场景数据格式&#xff0c;广泛用于存储和传输倾斜摄影测量、BIM、点云等大规模三维模型&#xff0c;尤其在国产地理信息与智慧城市项目中…

多语言共享贩卖机投资理财共享售卖机投资理财系统

多语言共享贩卖机投资理财/共享售卖机分红/充电宝/充电桩投资理财系统 采用thinkphp内核开发&#xff0c;支持注册赠金、多级分销&#xff0c;功能很基础 修复后台用户列表管理 可自定义理财商品 多种语言还可以添加任意语言 源码开源 多级分销 注册赠金等

[Windows] PDF 专业压缩工具 v3.0

[Windows] PDF 专业压缩工具 v3.0 链接&#xff1a;https://pan.xunlei.com/s/VOZwtC_5lCF-UF6gkoHuxWMoA1?pwdchg8# PDF 压缩工具 3.0 新版功能特点 - 不受页数限制&#xff01; 一、核心压缩功能 1.多模式智能压缩 支持 4 种压缩模式&#xff1a;平衡模式&#xff08…

SHEIN 希音 2026 校招 内推 查进度

SHEIN 希音 2026 校招 内推 查进度 &#x1f3e2;公司名称&#xff1a;SHEIN 希音 &#x1f4bb;招聘岗位&#xff1a;前端、后端、测试、产品、安全、运维、APP 研发、数据分析、设计师、买手、企划、招商、管培生 &#x1f31f;内推码&#xff1a;NTA2SdK &#x1f4b0;福利待…

ARM (6) - I.MX6ULL 汇编点灯迁移至 C 语言 + SDK 移植与 BSP 工程搭建

回顾一、核心关键字&#xff1a;volatile1.1 作用告诉编译器&#xff1a;被修饰的变量会被 “意外修改”&#xff08;如硬件寄存器的值可能被外设自动更新&#xff09;&#xff0c;禁止编译器对该变量进行优化&#xff08;如缓存到寄存器、删除未显式修改的代码&#xff09;。本…

Vue中使用keep-alive实现页面前进刷新、后退缓存的完整方案

Vue中使用keep-alive实现页面前进刷新、后退缓存的完整方案 在Vue单页应用中&#xff0c;路由切换时组件默认会经历完整的销毁-重建流程&#xff0c;这会导致两个典型问题&#xff1a;从搜索页跳转到列表页需要重新加载数据&#xff0c;而从详情页返回列表页又希望保留滚动位置…

Visual Studio Code 安装与更新故障排除:从“拒绝访问”到成功恢复

Visual Studio Code 安装与更新故障排除&#xff1a;从“拒绝访问”到成功恢复的实践分析 摘要&#xff1a; 本文旨在探讨 Visual Studio Code (VS Code) 在安装与更新过程中常见的故障&#xff0c;特别是涉及“拒绝访问”错误、文件缺失以及快捷方式和任务栏图标异常等问题。…

简单UDP网络程序

目录 UDP网络程序服务端 封装 UdpSocket 服务端创建套接字 服务端绑定 运行服务器 UDP网络程序客户端 客户端创建套接字 客户端绑定 运行客户端 通过上篇文章的学习&#xff0c;我们已经对网络套接字有了一定的了解。在本篇文章中&#xff0c;我们将基于之前掌握的知识…

如何解决 pip install 安装报错 ModuleNotFoundError: No module named ‘requests’ 问题

Python系列Bug修复PyCharm控制台pip install报错&#xff1a;如何解决 pip install 安装报错 ModuleNotFoundError: No module named ‘requests’ 问题 摘要 在日常Python开发过程中&#xff0c;pip install 是我们最常用的依赖安装命令之一。然而很多开发者在 PyCharm 控制台…

解释 ICT, Web2.0, Web3.0 这些术语的中文含义

要理解“ICT Web2.0”术语的中文含义&#xff0c;需先拆解为 ICT 和 Web2.0 两个核心概念分别解析&#xff0c;再结合二者的关联明确整体指向&#xff1a; 1. 核心术语拆解&#xff1a;中文含义与核心定义 &#xff08;1&#xff09;ICT&#xff1a;信息与通信技术 中文全称&am…

IDEA版本控制管理之使用Gitee

使用Gitee如果之前没用过Gitee&#xff0c;那么IDEA中应该长这样&#xff08;第一次使用&#xff09;如果之前使用过Gitee&#xff0c;那么IDEA中应该长这样这种情况&#xff0c;可以先退出Gitee&#xff0c;再拉取Gitee&#xff0c;退出Gitee方法见文章底部好&#xff0c;那么…

NLP(自然语言处理, Natural Language Processing)

让计算机能够理解、解释、操纵和生成人类语言&#xff0c;从而执行有价值的任务。 关注社区&#xff1a;Hugging Face、Papers With Code、GitHub 是现代NLP学习不可或缺的资源。许多最新模型和代码都在这里开源。 ①、安装库 pip install numpy pandas matplotlib nltk scikit…