ant简单的图片弹窗查看

先看效果

点击缩略图,弹出图片查看,滚动鼠标放大缩小查看图片,右上角x点击关掉查看图片。

弹窗

<a-modal
    :centered="true"
    :visible="visible"
    width="100%"
    :footer="null"
    :closable="false"
    :maskClosable="false"
    @cancel="closeImg"
  >
    <img
      v-if="showImg"
      @mousewheel="changeImg($event)"
      @mousedown="mousedown($event)"
      :height="height"
      :style="{'transform':'translate('+x+'px,'+y+'px)'}"
      id="imgId"
      draggable="false"
      :src="showImg"/>
    <a-icon
      class="close"
      @click="closeImg"
      type="close" />
  </a-modal>

定义变量

        visible: false,
        showImg: '',
        x:0,
        y:0,
        startx:'',
        starty:'',
        endx:0,
        endy:0,
        height: 800

方法

changeImg(e){
        if(e.deltaY<0)
          this.height += 80
        else
          if (this.height > 80)
            this.height -= 80
      },
      mousedown(e){
        this.startx=e.pageX
        this.starty=e.pageY
        document.addEventListener('mousemove',this.mousemove)
        document.getElementById('imgId').addEventListener('mouseup',this.mouseup)
      },
      mousemove(e){
        this.x=e.pageX-this.startx+this.endx
        this.y=e.pageY-this.starty+this.endy
      },
      mouseup(){
        // 解除绑定mousemove
        document.removeEventListener('mousemove',this.mousemove,false)
        this.endx=this.x
        this.endy=this.y
      },
      closeImg () {
        this.visible = false
        this.x = 0
        this.y = 0
        this.startx = ''
        this.starty = ''
        this.endx = 0
        this.endy = 0
        this.height = 800
      }

css


<style scoped lang="less">
/deep/.ant-modal-wrap{
  overflow: visible;
}
/deep/.ant-modal-content {
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  height: 100vh;
}
.close {
  position: fixed;
  right: 30px;
  top: 30px;
  color: white;
  font-size: 32px;
}
</style>

没实现旋转的效果,旋转用了拖动没效果了。

后面有时间在考虑一起实现。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你想了解有关 Ant Design Vue 中弹窗的内容吗?Ant Design Vue 是一个基于 Vue.js 的 UI 组件库,它提供了丰富的组件,包括弹窗(Modal)组件。你可以使用 Modal 组件来创建弹窗窗口。 要使用 Ant Design Vue 的弹窗组件,首先确保你已经按照官方文档中的指导安装和引入了 Ant Design Vue。然后,你可以按照以下步骤来创建一个弹窗: 1. 在你的 Vue 组件中引入 Modal 组件: ```vue <template> <div> <a-button @click="showModal">打开弹窗</a-button> <a-modal v-model="visible" title="这是一个弹窗"> <p>这是弹窗的内容。</p> </a-modal> </div> </template> <script> import { Modal, Button } from 'ant-design-vue'; export default { components: { 'a-modal': Modal, 'a-button': Button, }, data() { return { visible: false, }; }, methods: { showModal() { this.visible = true; }, }, }; </script> ``` 在这个示例中,我们引入了 Modal 和 Button 组件,并在点击按钮时设置 `visible` 变量为 `true`,从而显示弹窗。Modal 组件是一个带有标题和内容的弹窗容器,你可以在其中放置任意内容。 2. 根据你的需求,你可以自定义 Modal 组件的行为和样式。你可以在文档中查找更多关于 Modal 组件的信息,例如如何设置弹窗的宽度、高度、遮罩等。 这就是使用 Ant Design Vue 创建弹窗的基本步骤。你可以根据你的实际需求对弹窗进行进一步的定制和使用。希望这能帮到你!如果你还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值