<div class="floater-wrap" v-if="show" ref="floater" @click.stop="handleClick"
@touchstart.stop="handleTouchsrart('floater',$event)"
@touchmove.stop="handleTouchMove('floater',$event)">
<img src="../../assets/image/icon_xuanfu.png" alt="">
<span class="close" @click.stop="closeFloater">
<img src="../../assets/image/icon_close.png" alt="">
</span>
</div>
data(){
return{
coordinate: {
client: {},
elePosition: {}
}
}
},
methods:{
handleTouchsrart(refName, e) {
let element = e.targetTouches[0]
this.coordinate.client = {
x: element.clientX,
y: element.clientY
}
this.coordinate.elePosition.left = this.$refs[refName].offsetLeft
this.coordinate.elePosition.top = this.$refs[refName].offsetTop
},
handleTouchMove(refName, e) {
let element = e.targetTouches[0]
let x = this.coordinate.elePosition.left + (element.clientX - this.coordinate.client.x)
let y = this.coordinate.elePosition.top + (element.clientY - this.coordinate.client.y)
x = x <= 80 ? 80 : x >= innerWidth - this.$refs[refName].offsetWidth ? innerWidth - this.$refs[refName].offsetWidth : x
y = y <= 50 ? 50 : y >= innerHeight - this.$refs[refName].offsetHeight - 84 ? innerHeight - this.$refs[refName].offsetHeight - 84 : y
this.$refs[refName].style.top = y + 'px'
},
}