演示图如下:
代码如下
JS部分
Vue.component('dragIcon', {
template: `
<transition>
<div ref="dragIcon"
class="dragIcon"
@touchstart="handleTouchStart"
@touchmove.prevent="handleTouchMove"
@touchend="handleTouchEnd"
:style="{left: left + 'px',top: top + 'px',width: itemWidth + 'px',height: itemHeight + 'px'}"
v-text="text"
v-if="isShow"
>
</div>
</transition>
`,
props: {
text: {
type: String,
default: '首页'
},
itemWidth: {
type: Number,
default: 40
},
itemHeight: {
type: Number,
default: 40
}
},
data() {
return {
left: 0,
top: 0,
startToMove: false,
isShow: true,
timer: null,
currentTop: null,
clientW: document.documentElement.clientWidth,
clientH: document.documentElement.clientHeight
}
},
created () {
this.left = (this.clientW - this.it