当前位置:首页 > VUE

vue实现pc全屏滚动

2026-02-23 10:44:27VUE

实现PC全屏滚动的Vue方案

在Vue中实现全屏滚动效果,可以通过原生CSS结合Vue指令或使用第三方库完成。以下是两种常见方法:

使用原生CSS和Vue指令

通过CSS的height: 100vh实现全屏区块,配合Vue监听滚动事件切换页面:

<template>
  <div class="fullscreen-container" @wheel="handleWheel">
    <div 
      v-for="(section, index) in sections" 
      :key="index"
      class="fullscreen-section"
      :class="{ 'active': currentIndex === index }"
    >
      {{ section.content }}
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
      sections: [
        { content: '第一屏' },
        { content: '第二屏' },
        { content: '第三屏' }
      ],
      isScrolling: false
    }
  },
  methods: {
    handleWheel(e) {
      if (this.isScrolling) return;
      this.isScrolling = true;

      if (e.deltaY > 0 && this.currentIndex < this.sections.length - 1) {
        this.currentIndex++;
      } else if (e.deltaY < 0 && this.currentIndex > 0) {
        this.currentIndex--;
      }

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

<style>
.fullscreen-container {
  overflow: hidden;
}
.fullscreen-section {
  height: 100vh;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.8s ease;
}
</style>

使用第三方库vue-fullpage.js

对于更复杂的需求(如动画、锚点导航),推荐使用专为Vue设计的全屏滚动库:

  1. 安装依赖:

    vue实现pc全屏滚动

    npm install vue-fullpage.js --save
  2. 基础实现:

    
    <template>
    <full-page :options="options" ref="fullpage">
     <div class="section">第一屏内容</div>
     <div class="section">第二屏内容</div>
     <div class="section">第三屏内容</div>
    </full-page>
    </template>
import VueFullPage from 'vue-fullpage.js'

export default { components: { 'full-page': VueFullPage }, data() { return { options: { menu: '#navigation', anchors: ['page1', 'page2', 'page3'], sectionsColor: ['#41b883', '#ff5f45', '#0798ec'], navigation: true, scrollBar: false } } } }

vue实现pc全屏滚动

```

性能优化建议

  • 使用transform代替top/left定位实现动画,触发GPU加速
  • 对图片等资源进行懒加载,避免首屏加载过多内容
  • 移动端需添加touch事件支持
  • 考虑节流(throttle)处理滚动事件,避免过度触发

常见问题解决

滚动不流畅
检查是否有多余的CSS属性限制,如overflow: hidden未正确设置,或存在复杂的DOM结构影响渲染性能。

导航点位置偏移
确保父容器没有额外的padding或margin,全屏区块应直接作为body的子元素。

移动端适配
需额外处理touch事件,并考虑禁用浏览器默认的滚动行为:

document.addEventListener('touchmove', function(e) {
  e.preventDefault();
}, { passive: false });

标签: 全屏vue
分享给朋友:

相关文章

vue element实现

vue element实现

Vue Element UI 实现 Vue Element UI 是基于 Vue.js 的组件库,提供丰富的 UI 组件,适合快速开发企业级中后台产品。以下是一些关键实现方法和步骤: 安装 Vue…

vue实现海报

vue实现海报

Vue 实现海报生成方案 使用 html2canvas 库 html2canvas 是一个将 HTML 元素转换为 Canvas 的库,适合将 Vue 组件渲染为海报图片 安装依赖: npm in…

vue实现组件

vue实现组件

Vue 组件实现基础 Vue 组件是可复用的 Vue 实例,用于封装 UI 和逻辑。通过 .vue 文件或直接注册组件实现。 单文件组件 (SFC) 示例 <template>…

vue实现tab

vue实现tab

Vue 实现 Tab 切换功能 在 Vue 中实现 Tab 切换功能可以通过多种方式完成,以下是几种常见的实现方法: 使用 v-if 和 v-show 指令 通过绑定 v-if 或 v-show 来…

vue框架实现CRM

vue框架实现CRM

Vue框架实现CRM系统 使用Vue框架构建CRM(客户关系管理)系统需要结合前端技术栈和后端API。以下为关键实现方法: 技术选型 核心框架:Vue 3(Composition API) UI组件…

vue  实现关联属性

vue 实现关联属性

Vue 实现关联属性 在 Vue 中实现关联属性通常涉及计算属性(computed properties)或侦听器(watchers),用于根据其他属性的变化动态更新目标属性。 使用计算属性 计算属…