Commit 19d7a647 by 杨北旺

二维码添加拖动功能

1 parent be4b0867
<template>
<div class="qr-code-components">
<div :style="[{bottom:bottom+'px'}]" @mouseenter="show = true" @mouseleave="show = false" class="right_btn flex_ccc">
<div :style="[{ bottom: bottom + 'px' }]" @mousedown="move" @mouseup="moveEnd" ref="callCenter" @mouseenter="show = true" @mouseleave="show = false" class="right_btn flex_ccc">
<img src="../../assets/contact_icon.png" />
<div class="contact_text">联系我们</div>
</div>
<div :style="[{bottom:bottom+'px'}]" v-if="show" class="left_code flex_ccc">
<img :src="codeUrl" />
<div style="height: 16px"></div>
<span class="h18_title">服务热线</span>
<span class="h18_title">{{phone}}</span>
<div v-if="show" class="left_code flex_ccc">
<img :src="codeUrl" />
<div style="height: 16px"></div>
<span class="h18_title">服务热线</span>
<span class="h18_title">{{ phone }}</span>
</div>
</div>
</div>
</template>
......@@ -21,13 +21,13 @@ export default {
type: Number,
default: 64
},
codeUrl:{
type:String,
default:'https://img01.glsx.com.cn/weapp/resource/equity-h5-new/qrcode2.jpg'
codeUrl: {
type: String,
default: 'https://img01.glsx.com.cn/weapp/resource/equity-h5-new/qrcode2.jpg'
},
phone:{
type:String,
default:'189 0000 1234'
phone: {
type: String,
default: '189 0000 1234'
}
},
data() {
......@@ -35,15 +35,57 @@ export default {
show: false
}
},
methods: {}
methods: {
// 拖动窗口,鼠标按下
move(event) {
// 给对应div添加拖拽属性
let callCenter = this.$refs.callCenter
callCenter.style.cursor = 'move'
var distanceX = event.clientX - callCenter.offsetLeft
var distanceY = event.clientY - callCenter.offsetTop
// 获取按下时对应的坐标
this.startX = event.pageX
this.startY = event.pageY
document.onmousemove = function (ev) {
var oevent = ev || event
// 加入判断,让浮窗在限定的页面内可拖动
if (ev.clientX < 40 || ev.clientX > document.body.clientWidth - 30) {
return
}
if (ev.clientY < 40 || ev.clientY > document.body.clientHeight - 30) {
return
}
callCenter.style.left = oevent.clientX - distanceX + 'px'
callCenter.style.top = oevent.clientY - distanceY + 'px'
}
document.onmouseup = function () {
document.onmousemove = null
document.onmouseup = null
callCenter.style.cursor = 'default'
}
},
// 鼠标抬起触发
moveEnd(event) {
// 获取鼠标抬起时的坐标
this.endX = event.pageX
this.endY = event.pageY
// 计算按下与抬起位置差值
var d = Math.sqrt((this.startX - this.endX) * (this.startX - this.endX) + (this.startY - this.endY) * (this.startY - this.endY))
if (d === 0 || d < 7) {
// console.log('执行了点击事件')
} else {
// console.log('执行了拖拽事件')
}
}
}
}
</script>
<style lang="scss" scoped>
.qr-code-components {
.left_code {
position: fixed;
right: 77px;
bottom: 64px;
position: absolute;
right: 57px;
bottom: 0px;
width: 144px;
height: 201px;
background: #ffffff;
......
......@@ -182,7 +182,7 @@ export default {
tip: '秒杀、抽奖、满减等'
},
{
title: '直播间直播',
title: '直播间准备',
tip: '地点、灯光、布景等'
}
],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!