Vue-cli 实现拖拽窗口


<template>
  <div id="ElementWind" v-show="isOpenWind " class="dragclass"  @mousedown="drag">
    <div id="imgHead">
      <a href="#"  @click="isOpenWind = false">x</a>
    </div>
    <div id="imgBody">
      <div id="imgContent"></div>
      <div id="imgBtn"></div>
    </div>
  </div>
</template>
<script>
export default {
   data(){
      return {
        isOpenWind :true  //点击X关闭窗口
      }
   },
   methods:{
     //鼠标按下拖拽
     drag(e){
        // console.log(e)
        var oDiv = e.path[1];
        var disX = e.clientX - oDiv.offsetLeft;
        var disY = e.clientY - oDiv.offsetTop;
        document.onmousemove = function(e){
            e.preventDefault();
            var l = e.clientX - disX;
            var t = e.clientY - disY;
            oDiv.style.left = l + "px"
            oDiv.style.top = t + "px"
        } 
        document.onmouseup = function(){
            document.onmousemove = null;
            document.onmouseup = null;
        }
     }
   }
}
</script>

<style scoped>
#ElementWind {
  text-align: center;
  width: 500px;
  height: 377px;
  position: absolute;
  left: 15px;
  bottom: 250px;
  border: 1px solid #57a3f3;
  background: #fff;
}

a {
  padding-right: 5px;
  text-decoration: none;
  color: #fff;
}

a:hover {
  color: #fff;
}

#imgHead {
  width: calc(100% + 1px);
  text-align: right;
  padding: 4px 0;
  /* border: 1px solid #003399; */
  background: #57a3f3;
  font-size: 11px;
  color: #3366ff;
  cursor: move;
  /* margin-top: -21px; */
}

#imgHead a:link,
#imgHead a:visited {
  font-size: 14px;
  font-weight: bold;
  padding: 0 3px;
}

#imgBody {
  width: 100%;
  height: calc(100% - 23px);
  /* margin-top: -21px; */
  text-align: center;
}

#imgContent {
  height: 324px;
  padding: 2px;
  /* margin-top: -21px; */
  /* overflow-y: scroll; */
  /* word-break: break-all */
}

#imgBtn {
  width: 100%;
  height: 22px;
  background-color: #ccc;
  /* margin-top: -21px;   */
}

</style>

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值