当前位置:首页 > VUE

vue实现折纸翻书

2026-03-08 23:18:41VUE

Vue实现折纸翻书效果

要实现折纸翻书效果,可以利用CSS 3D变换和Vue的动画过渡功能。以下是一个基本实现方案:

基础HTML结构

<template>
  <div class="book-container">
    <div class="book" @click="flipPage">
      <div class="page front" :class="{ 'flipped': isFlipped }">
        Front Content
      </div>
      <div class="page back" :class="{ 'flipped': isFlipped }">
        Back Content
      </div>
    </div>
  </div>
</template>

Vue组件脚本

<script>
export default {
  data() {
    return {
      isFlipped: false
    }
  },
  methods: {
    flipPage() {
      this.isFlipped = !this.isFlipped
    }
  }
}
</script>

CSS样式

.book-container {
  perspective: 1000px;
  width: 300px;
  height: 400px;
}

.book {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  cursor: pointer;
}

.page {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  transition: transform 1s;
  border: 1px solid #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.front {
  background-color: #f5f5f5;
  transform: rotateY(0deg);
  z-index: 2;
}

.back {
  background-color: #e5e5e5;
  transform: rotateY(180deg);
}

.front.flipped {
  transform: rotateY(-180deg);
}

.back.flipped {
  transform: rotateY(0deg);
}

多页翻书实现

对于多页翻书效果,可以使用动态组件和过渡:

<template>
  <div class="book">
    <transition name="flip" mode="out-in">
      <div :key="currentPage" class="page">
        {{ pages[currentPage] }}
      </div>
    </transition>
    <button @click="prevPage">Previous</button>
    <button @click="nextPage">Next</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentPage: 0,
      pages: [
        'Page 1 Content',
        'Page 2 Content',
        'Page 3 Content'
      ]
    }
  },
  methods: {
    prevPage() {
      if (this.currentPage > 0) {
        this.currentPage--
      }
    },
    nextPage() {
      if (this.currentPage < this.pages.length - 1) {
        this.currentPage++
      }
    }
  }
}
</script>
.flip-enter-active, .flip-leave-active {
  transition: all 0.7s;
}

.flip-enter {
  transform: rotateY(90deg);
  opacity: 0;
}

.flip-leave-to {
  transform: rotateY(-90deg);
  opacity: 0;
}

.page {
  width: 300px;
  height: 400px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 20px auto;
  border: 1px solid #ddd;
}

高级3D翻页效果

要实现更逼真的3D翻页效果,可以使用CSS clip-path和transform-origin:

vue实现折纸翻书

.page {
  position: absolute;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transition: transform 1s;
  backface-visibility: hidden;
}

.page.flipping {
  transform: rotateY(-180deg);
  box-shadow: 5px 5px 15px rgba(0,0,0,0.3);
}

这种方法可以创建更真实的书本翻页效果,通过调整transform-origin和阴影效果增强立体感。

标签: 翻书vue
分享给朋友:

相关文章

vue实现导航切换内容

vue实现导航切换内容

Vue实现导航切换内容的方法 在Vue中实现导航切换内容,可以通过以下方式实现: 使用动态组件 动态组件通过<component :is="currentComponent">实现内容切…

ssh vue 实现

ssh vue 实现

使用SSH连接Vue项目部署的服务器 在Vue项目开发或部署过程中,可能需要通过SSH连接到远程服务器进行配置或维护。以下是实现SSH连接并部署Vue项目的关键步骤: 生成SSH密钥对 在本地终端运…

vue实现ide

vue实现ide

Vue 实现 IDE 的基本思路 使用 Vue 构建一个简易的集成开发环境(IDE)需要整合代码编辑器、文件管理、终端模拟等功能。以下是关键实现步骤和推荐工具。 核心功能模块 代码编辑器 使用…

vue实现uuid

vue实现uuid

使用 uuid 库生成 UUID 在 Vue 项目中,可以使用 uuid 库来生成 UUID。安装依赖: npm install uuid 在 Vue 组件中使用: import { v4 as…

vue实现webshell

vue实现webshell

Vue 实现 WebShell 使用 Vue 实现 WebShell 需要结合前端与后端的交互,通常通过 WebSocket 或 HTTP 协议与服务器通信。以下是一个基于 Vue 和 WebSock…

vue前端实现

vue前端实现

Vue 前端实现基础步骤 安装 Vue.js 和相关依赖 通过 npm 或 yarn 安装 Vue.js,建议使用 Vue CLI 快速搭建项目。运行命令 npm install -g @vue/cl…