vue实现移动端可拖拽浮动球按钮
<template>
<transition>
<div ref="dragIcon" class="dragIcon" @click="onBtnClicked" @touchstart.stop="handleTouchStart" @touchmove.prevent.stop="handleTouchMove($event)" @touchend.stop="handleTouchEnd"
:style="{left: left + 'px',top: top + 'px',width: itemWidth + 'px',height: itemHeight + 'px'}" v-if="isShow">
<slot></slot>
</div>
</transition>
</template>
<script>
export default {
props: {
itemWidth: {
type: Number,
default: 50,
},
itemHeight: {
type: Number,
default: 50,
},
},
data() {
return {
left: 0,
top: 0,
startToMove: false,
isShow: true,
timer: null,
currentTop: null,
clientW: document.documentElement.clientWidth,
clientH: document.documentElement.clientHeight,
}
}