当前位置:首页 > VUE

vue实现盖章

2026-03-27 11:09:37VUE

在Vue中实现盖章效果

在Vue中实现盖章效果可以通过CSS动画和动态组件来实现。以下是一个常见的实现方法:

使用CSS动画实现盖章效果

创建一个盖章动画效果,可以通过CSS的transform和transition属性实现:

<template>
  <div class="stamp-container">
    <div 
      class="stamp" 
      :class="{ 'stamp-active': isStamping }"
      @click="handleStamp"
    >
      盖章
    </div>
    <div class="stamp-result" v-if="showStamp">
      <img src="stamp-image.png" alt="印章">
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isStamping: false,
      showStamp: false
    }
  },
  methods: {
    handleStamp() {
      this.isStamping = true
      setTimeout(() => {
        this.isStamping = false
        this.showStamp = true
      }, 500)
    }
  }
}
</script>

<style>
.stamp {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: red;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.stamp-active {
  transform: scale(0.9);
}

.stamp-result {
  position: absolute;
  animation: stampEffect 0.5s ease;
}

@keyframes stampEffect {
  0% {
    transform: scale(1.2);
    opacity: 0.5;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
</style>

使用SVG实现动态印章

如果需要更复杂的印章效果,可以使用SVG:

<template>
  <div>
    <button @click="stamp = !stamp">盖章</button>
    <svg v-if="stamp" width="200" height="200">
      <circle cx="100" cy="100" r="80" fill="none" stroke="red" stroke-width="5"/>
      <text x="100" y="110" text-anchor="middle" fill="red" font-size="24">公司印章</text>
      <text x="100" y="140" text-anchor="middle" fill="red" font-size="16">2023</text>
    </svg>
  </div>
</template>

<script>
export default {
  data() {
    return {
      stamp: false
    }
  }
}
</script>

实现位置固定的印章

如果需要将印章固定在文档的特定位置:

<template>
  <div class="document-container">
    <div class="document-content">
      <!-- 文档内容 -->
    </div>
    <div class="stamp-fixed" v-if="showStamp">
      <div class="stamp-image"></div>
    </div>
  </div>
</template>

<style>
.document-container {
  position: relative;
}

.stamp-fixed {
  position: absolute;
  right: 50px;
  bottom: 50px;
}

.stamp-image {
  width: 150px;
  height: 150px;
  background-color: rgba(255, 0, 0, 0.1);
  border: 3px solid red;
  border-radius: 50%;
}
</style>

使用第三方库实现复杂印章

对于更专业的印章效果,可以考虑使用第三方库如fabric.js:

vue实现盖章

import { fabric } from 'fabric'

export default {
  mounted() {
    const canvas = new fabric.Canvas('canvas')
    const stamp = new fabric.Circle({
      radius: 50,
      fill: 'transparent',
      stroke: 'red',
      strokeWidth: 3,
      left: 100,
      top: 100
    })
    canvas.add(stamp)
  }
}

以上方法可以根据具体需求选择使用,从简单的CSS动画到复杂的SVG或Canvas实现,都能在Vue中创建出满意的盖章效果。

标签: vue
分享给朋友:

相关文章

vue实现导航栏切图

vue实现导航栏切图

Vue 实现导航栏切图 使用 Vue Router 实现基础导航 在 Vue 项目中,可以通过 Vue Router 实现导航栏的路由切换。创建一个导航栏组件,并在其中使用 <router-li…

vue   实现单选

vue 实现单选

Vue 实现单选功能 在 Vue 中实现单选功能可以通过多种方式,以下是几种常见的方法: 使用原生 <input type="radio"> 绑定 v-model 通过 v-model…

vue实现标签

vue实现标签

Vue 实现标签的方法 在 Vue 中实现标签功能可以通过多种方式完成,以下是几种常见的方法: 使用动态组件 动态组件可以根据不同的条件渲染不同的标签内容。通过 :is 属性动态绑定组件名,实现标签…

实现vue datepicker

实现vue datepicker

安装依赖 使用 vue-datepicker 或第三方库如 v-calendar 或 vue2-datepicker。以 vue2-datepicker 为例: npm install vue2…

vue实现评分

vue实现评分

Vue 实现评分功能 使用组件库实现 安装 element-ui 或 ant-design-vue 这类 UI 库,它们已经内置了评分组件。 以 element-ui 为例: <templa…

vue实现刷卡

vue实现刷卡

Vue 实现刷卡效果 在 Vue 中实现刷卡效果可以通过 CSS 动画和 Vue 的过渡系统结合完成。以下是一种常见的实现方式: 基础实现方法 安装 Vue 过渡依赖(如果尚未安装): npm i…