vue实现全屏滚动
Vue 实现全屏滚动的方法
全屏滚动效果常见于单页应用,通过滚动页面切换全屏区块。以下是几种实现方式:
使用 vue-fullpage.js 插件
安装依赖:
npm install vue-fullpage.js
基本用法:

import Vue from 'vue'
import fullpage from 'vue-fullpage.js'
Vue.use(fullpage)
// 组件中使用
<template>
<full-page :options="options">
<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>
自定义实现方案
监听滚动事件实现:
// 在mounted中
window.addEventListener('wheel', this.handleScroll, { passive: false })
methods: {
handleScroll(e) {
e.preventDefault()
const direction = e.deltaY > 0 ? 'down' : 'up'
// 根据方向执行滚动动画
}
}
CSS关键样式:

html, body {
overflow: hidden;
}
.section {
height: 100vh;
width: 100%;
position: relative;
}
结合 CSS scroll-snap
纯CSS方案:
.container {
scroll-snap-type: y mandatory;
overflow-y: scroll;
height: 100vh;
}
.section {
scroll-snap-align: start;
height: 100vh;
}
Vue组件结构:
<div class="container">
<div class="section" v-for="(item, index) in sections" :key="index">
{{ item.content }}
</div>
</div>
注意事项
- 移动端需添加touch事件处理
- 考虑浏览器兼容性问题
- 过度滚动可能导致性能问题
- 销毁组件时移除事件监听
以上方案可根据项目需求选择,插件方案更完善但体积较大,自定义方案更灵活但需处理更多细节。






