当前位置:首页 > VUE

vue实现fullpage

2026-03-27 14:54:59VUE

Vue 实现 FullPage 滚动效果

使用 Vue 实现全屏滚动(FullPage)效果可以通过原生开发或借助现有库完成。以下是两种常见方法:

使用 vue-fullpage.js 库

安装 vue-fullpage.js:

npm install vue-fullpage.js --save

在 Vue 项目中引入并注册组件:

import Vue from 'vue'
import VueFullPage from 'vue-fullpage.js'

Vue.use(VueFullPage)

在模板中使用:

<template>
  <full-page ref="fullpage" :options="options">
    <div class="section">第一屏内容</div>
    <div class="section">第二屏内容</div>
    <div class="section">第三屏内容</div>
  </full-page>
</template>

<script>
export default {
  data() {
    return {
      options: {
        licenseKey: 'YOUR_KEY',
        scrollingSpeed: 700,
        navigation: true
      }
    }
  }
}
</script>

<style>
.section {
  height: 100vh;
  width: 100%;
}
</style>

原生实现 FullPage 效果

通过监听滚轮事件和 CSS 过渡实现基础效果:

vue实现fullpage

<template>
  <div class="fullpage-container" ref="container">
    <div 
      v-for="(page, index) in pages" 
      :key="index"
      class="page"
      :style="{ transform: `translateY(${currentIndex * -100}vh)` }"
    >
      {{ page.content }}
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
      pages: [
        { content: '第一屏' },
        { content: '第二屏' },
        { content: '第三屏' }
      ],
      isScrolling: false
    }
  },
  mounted() {
    window.addEventListener('wheel', this.handleWheel)
  },
  beforeDestroy() {
    window.removeEventListener('wheel', this.handleWheel)
  },
  methods: {
    handleWheel(e) {
      if (this.isScrolling) return

      this.isScrolling = true

      if (e.deltaY > 0) {
        this.currentIndex = Math.min(this.currentIndex + 1, this.pages.length - 1)
      } else {
        this.currentIndex = Math.max(this.currentIndex - 1, 0)
      }

      setTimeout(() => {
        this.isScrolling = false
      }, 800)
    }
  }
}
</script>

<style>
.fullpage-container {
  overflow: hidden;
  height: 100vh;
}

.page {
  height: 100vh;
  width: 100%;
  transition: transform 0.8s ease;
}
</style>

注意事项

  • 移动端需要额外处理 touch 事件
  • 原生实现需要考虑浏览器兼容性
  • 性能优化:使用 will-change 或硬件加速
  • 路由同步:如需保持 URL 与当前页面对应,需结合 vue-router

两种方法各有优势:使用库更快速但灵活性较低,原生实现更可控但开发成本较高。根据项目需求选择合适方案。

标签: vuefullpage
分享给朋友:

相关文章

vue el 实现

vue el 实现

Vue 中使用 Element UI (el) 的实现方法 Element UI 是一个基于 Vue 的组件库,提供丰富的 UI 组件,常用于快速构建企业级中后台产品。以下介绍 Vue 项目中集成和使…

vue实现ios

vue实现ios

Vue 实现 iOS 风格应用 使用 Vue 实现 iOS 风格的应用,可以通过结合 UI 框架和自定义样式来达成目标。以下是具体方法和步骤: 选择 iOS 风格的 UI 框架 Vue 生态中有多…

vue computed实现

vue computed实现

计算属性的基本用法 在Vue中,计算属性通过computed选项定义,用于声明依赖于其他属性的动态值。计算属性基于它们的依赖进行缓存,只有依赖发生变化时才会重新计算。 new Vue({ dat…

vue实现menu

vue实现menu

Vue 实现 Menu 的方法 使用 Element UI 的 Menu 组件 Element UI 提供了现成的 Menu 组件,适合快速实现导航菜单。安装 Element UI 后,可以直接使用…

vue实现computed

vue实现computed

Vue 中 computed 的实现原理 computed 属性是 Vue 的一个核心特性,它基于响应式依赖进行缓存,仅在依赖发生变化时重新计算。以下是 computed 的实现方式: 基本用法 在…

vue实现ftp

vue实现ftp

Vue 中实现 FTP 功能 Vue 本身是一个前端框架,无法直接操作 FTP 协议(FTP 通常需要后端支持)。以下是两种常见实现方式: 前端与后端配合实现 FTP 前端通过 API 与后端通信,…