vue拖拽弹窗

最近一直在忙着大屏项目,iview中的弹窗不能满做我拖拽的需求,就自己写了一个。

小面这张图片是弹窗的样式

弹窗样式


<template>
 <!--
  * Developer: shiyzhang
  * Date: 2020/08/27
  * email: zsyou0911@163.com
 -->
  <!-- 弹框 -->
  <div id="popupBox1" :style="{'top':top,'left':left,'width':width}" v-if="show" ref="movediv">
    <div class="poput_contant1" >
    <!--   关闭背景图  可替换成自己的背景图  -->
      <span @click="closePopu()" class="pop_close1"></span>
      <h3  class="pop_title1"  @mousedown="move">
        <span class="pop_name1">{{title}}</span>
      </h3>
      <div class="pop_main1 scrollbar_box" :style="{'maxHeight':maxHeight}" id="tableShow">
        <div class="pop_m_box1 scrollbar_box1">
          <!-- 载入动画 -->
          <div class="loadEffect1 scrollbar_box1">
            <slot></slot>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'popubox',
  props: {
    title: {
      type: String,
      default: '明细' // 弹窗标题
    },
    top: { // 弹窗上边边可视窗口距离
      type: String,
      default: '30%' // 220% 50px
    },
    left: { // 弹窗左边可视窗口距离
      type: String,
      default: '30%' // 220% 50px
    },
    width: String, // 弹窗宽度 220% 50px
    maxHeight: { // 弹窗最小高度
      type: String,
      default: '400px' // 220% 50px
    },
    show: Boolean // 弹窗显示隐藏

  },

  // computed:{
  //   show(){
  //     console.log(this.show,'组件')
  //   }
  // },
  methods: {
    // 关闭弹窗
    closePopu () {
      this.$emit('update:show', false)
      // this.$emit('closePopu')
    },
    // 弹窗拖拽事件
    move (e) {
      let odiv = this.$refs.movediv // 获取当前元素
      // 算出鼠标相对元素的位置
      let disX = e.clientX - odiv.offsetLeft
      let disY = e.clientY - odiv.offsetTop
      console.log('disX', disX, 'disY', 0 - disY)
      document.onmousemove = (e) => {
        // 用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
        let left = e.clientX - disX
        let top = e.clientY - disY
        let clH = document.documentElement.clientHeight - odiv.clientHeight 
        let clW = document.documentElement.clientWidth - odiv.clientWidth
        if (left <= 0) left = 0
        if (left >= clW) left = clW
        if (top <= 0) top = 0
        if (top >= clH)top = clH
        // 移动当前元素
        odiv.style.left = left + 'px'
        odiv.style.top = top + 'px'
      }
      document.onmouseup = (e) => {
        document.onmousemove = null
        document.onmouseup = null
      }
    }
  }
}
</script>

<style lang='less'  type="text/scss" scoped >
  /* 弹框样式 */
  #popupBox1 {
    position: fixed;
    z-index: 99999;
    border-radius: 4px;
  }
  .poput_contant1 {
    width: 100%;
    height: 100%;
    position: relative;
  }

  .poput_contant1 .pop_title1 {
    height: 45px;
    cursor: default;
    line-height: 45px;
    background: linear-gradient(120deg, rgba(34, 84, 127, 1) 0%, rgba(34, 84, 127, 1) 0%, rgba(91, 255, 255, 1) 100%, rgba(91, 255, 255, 1) 100%);
  }

  .pop_name1 {
    font-size: 30px;
    font-weight: bold;
    color: #5BFFFF;
    padding-left: 40px;
  }

  .pop_close1 {
    display: inline-block;
    float: right;
    height: 45px;
    width: 45px;
    z-index: 1000000;
    background: url(../../images/close_btn.png) no-repeat center;
    background-size: 50% 50%;
    margin-right: 0;
    margin-top: 0;
    cursor: pointer;
  }

  .pop_main1 {
    /*height: calc(100% - 45px);*/
    background: linear-gradient(140deg, rgba(34, 84, 127, 1) 0%, rgba(34, 84, 127, 1) 58%, rgba(91, 255, 255, 1) 100%, rgba(91, 255, 255, 1) 100%);
    /*overflow: hidden;*/
    overflow-y: auto;
    box-sizing: border-box;
    padding: 8px;
  }

  .pop_m_box1 {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    background: #f1f1f1;
  }
  /* 滚动条样式 */
  .scrollbar_box1 {
    overflow: hidden;
    overflow-y: auto
  }

  .scrollbar_box1::-webkit-scrollbar {
    width: 10px;
    background: #295a86;
    border-radius: 2px;
  }
  .scrollbar_box1::-webkit-scrollbar-thumb {
    width: 4px;
    background: #548bb7;
    border-radius: 10px;
  }
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

万水千山走遍TML

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

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

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

打赏作者

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

抵扣说明:

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

余额充值