手机端拖动事件是touchstart touchmove touchend,对用pc端的mousedown mousemove mouseup事件,下面实现了一个兼容手机端和pc端的vue拖放代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />
<style>
.xuanfu {
height: 4.5rem;
width: 4.5rem;
z-index: 990;
position: fixed;
top: 4.2rem;
right: 3.2rem;
border-radius: 0.8rem;
background-color: rgba(0, 0, 0, 0.55);
}
.yuanqiu {
height: 2.7rem;
width: 2.7rem;
border: 0.3rem solid rgba(140, 136, 136, 0.5);
margin: 0.65rem auto;
color: #000000;
font-size: 1.6rem;
line-height: 2.7rem;
text-align: center;
border-radius: 100%;
background-color: #ffffff;
}
</style>
</head>
<body>
<div id="app">
<div id="customer">
<!-- Suspended HTML -->
<div ref="moveDiv" class="xuanfu" id="div2" @mousedown="down" @touchstart="down" @mousemove="move" @touchmove="move" @mouseup="end" @touchend="end">
<div class="yuanqiu">
</div>
</div>
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue.2.2.min.js"></script>
<script>
new Vue({
el: '#app',
data:function() {
return {
flags: false,
position: {
x: 0,
y: 0
},
nx: '', ny: '', dx: '', dy: '', xPum: '', yPum: '',
}
},
methods: {
// Mobile drag
down(){
this.flags = true;
var touch ;
if(event.touches){
touch = event.touches[0];
}else {
touch = event;
}
this.position.x = touch.clientX;
this.position.y = touch.clientY;
this.dx = this.$refs.moveDiv.offsetLeft;
this.dy = this.$refs.moveDiv.offsetTop;
},
move(){
if(this.flags){
var touch ;
if(event.touches){
touch = event.touches[0];
}else {
touch = event;
}
this.nx = touch.clientX - this.position.x;
this.ny = touch.clientY - this.position.y;
this.xPum = this.dx+this.nx;
this.yPum = this.dy+this.ny;
this.$refs.moveDiv.style.left = this.xPum+"px";
this.$refs.moveDiv.style.top = this.yPum +"px";
//Prevent page from sliding default events
document.addEventListener("touchmove",function(){
event.preventDefault();
},false);
}
},
//Function when mouse is released
end(){
this.flags = false;
},
}
})
</script>
</body>
</html>
网友回复
python如何利用ai自动在千牛监听和回复用户消息促成用户下单购买?
ai如何自动监听和回复咸鱼的消息?
如何解决three的三维场景CSS3DObject中iframe穿透一切问题呢?
有没有哪个ai人工智能动态生成鲜活带表情肢体动作逼真数字人与人类交流视频聊天?
threejs如何将iframe与video作为立方体模型一面的材质可点击交互?
UEFI与Legacy启动有啥不同?
可在u盘启动的开源匿名操作系统有哪些?
Pyloid与Pywebview打包生成桌面应用区别?
win10的iso镜像如何通过u盘来安装?
如何解决输入sora2邀请码报错:Sora is not available in The Netherlands yet