前端实现附件预览添加水印

最简单

的前端实现预览时添加水印,添加个图层在上方写上水印渲染即可,然后实现穿透顶层元素点击底部元素,实现水印效果,css3属性:pointer-events的妙用
先看效果
在这里插入图片描述

<template>
  <div>
    <el-dialog
      modal-append-to-body
      append-to-body
      title="预览"
      :visible.sync="dialogPreviewVisible"
      width="100%"
      close-on-press-escape
      fullscreen
      :before-close="handleClose"
    >
    <!-- 水印图层 -->
      <div class="watermark">
        <span class="watermark-span" v-for="(item, index) in 30" :key="index"
          >张三-xxx部门</span
        >
      </div>
      <!-- 附件预览图层 -->
      <iframe width="100%" name="ifd" src="https://www.chinanews.com.cn/gj/2023/09-05/10072440.shtml" frameborder="0"></iframe>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    iframeUrl: "",
    dialogPreviewVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  methods: {
    handleClose(done) {
      this.$emit("closeDialog");
    },
  },
};
</script>

<style lang="scss" scoped>
// 水印文案样式
.watermark-span {
  transform: rotate(340deg); //让字体的角度倾斜
  font-size: 18px;
  font-weight: 500;
  padding: 6rem; //水印文案间距调大 
  color: #949494b8;
  user-select: none;
}
// 水印图层样式
.watermark {
  pointer-events: none; //穿透顶层元素点击底部元素,实现水印效果
  overflow: hidden;
  position: absolute;
  background: #ff000000;
  width: 100%;
  display: flex;
  height: 100%;
  // transform: rotate(345deg);
  justify-content: space-between;
  flex-wrap: wrap;
}
 ::v-deep .el-dialog__body {
    flex: 1;
    overflow: auto;
    display: flex;
    position: relative;
    // flex-direction: column;
  }
s iframe {
  height: 100%;
}
</style>

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吃西瓜不吐籽_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值