vue的拖动div

vue的拖动div

在这里插入图片描述
双击元素可以拖动
在这里插入图片描述
代码

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>字典数据</title>
		<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
		<!--<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"/>-->
		<script src="https://unpkg.com/element-ui/lib/index.js"></script>
		<style type="text/css">
			.ds{
				width: 500px;
				height: 500px;
				background: yellowgreen;
			}
			.cs{
				display: inline-block;
				width: 50px;height: 50px;
			}
		</style>
	</head>

	<body>
		<div id="app">
			<template>
				<div>
				<div class="ds"
					@mousedown="down"
				  	@mouseup="up" 
				  	@dblclick="dblclick"
				  	@mousemove="move" 
				  	@mouseleave="out"
				  	@mouseout ="outs" 
				  	@mouseenter="enter" 
				  	@mouseover="enters"  
					>
				  	<div
					class="cs"
					v-for="(item,index) in list" :key="index"
					:style="listcss[index]"
					 @dblclick="dblclicks(index)"
				  	>{{item.name}}</div>
				</div>
				</div>
			</template> 
		</div>
		<script>
			new Vue({
				el: '#app',
				data: function() {
					return {
						time:'', 
						list:[{name:"1"},{name:"2"},{name:"3"}],
						listcss:[{left:0,top:0,position:'static',background:'red'},
						{left:0,top:0,position:'static',background:'#00fff3'},
						{left:0,top:0,position:'static',background:'#00ff08'},
						],
						show:false,
						mods:0,
					}
				},
				mounted() {
				},
				methods: {
					 down(e){
					 	console.log("按下")
					 },
					 up(){console.log("抬起")},
					 dblclick(){
					 	console.log("双击")},
					 	dblclicks(val){
					 		this.mods=val;
					 		if(this.show==false){
					    	 this.show=true;
					    }else{
					    	 this.show=false;
					    }
					    console.log(val)
					 	},
					 move(e){
					 	if(this.show==true){
					 		 this.listcss[this.mods].left=e.x+'px';
					 	     this.listcss[this.mods].top=e.y+'px';
					 	     this.listcss[this.mods].position="absolute";
					 	}
					 	console.log(e.x+","+e.y)},
					 out(){console.log("离开")},
					 outs(){console.log("移开")},
					 enter(){console.log("进入")},
					 enters(){console.log("在")},
				}
			})
		</script>
	</body>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值