当前位置:首页 > 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实例并定义数据 new Vue({ el: '#app', data: { letters…

vue全选实现

vue全选实现

Vue 全选实现方法 在 Vue 中实现全选功能通常涉及数据绑定和事件处理。以下是几种常见的实现方式: 基础实现方式 <template> <div> <…

vue实现autocomplete

vue实现autocomplete

Vue 实现 Autocomplete 功能 Vue 中实现 Autocomplete(自动完成)功能可以通过自定义组件或使用现有库完成。以下是几种常见方法: 方法一:使用 Vue 原生实现 创建…

vue 全景实现

vue 全景实现

Vue 全景实现方案 在Vue中实现全景效果,通常需要结合WebGL或第三方库来处理3D场景渲染。以下是几种常见方法: 使用Three.js库 Three.js是一个强大的WebGL库,适合创建3D…

vue 实现分屏

vue 实现分屏

Vue 实现分屏的方法 使用 CSS Flexbox 或 Grid 布局 通过 CSS Flexbox 或 Grid 布局可以轻松实现分屏效果。在 Vue 组件中定义两个或多个区域,并使用 CSS 控…

vue实现加减

vue实现加减

Vue 实现加减功能 在 Vue 中实现加减功能可以通过数据绑定和事件监听来完成。以下是一个简单的实现方法: 模板部分 <template> <div> <…