拖拽示例

Posted liuhao-web

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了拖拽示例相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
<button class="button">开始</button>
<button class="button">关闭</button>
<button class="button">注册</button>

<div id="con" style="width:500px;height:500px;background: yellow;margin-top: 100px"></div>
<script>
var moveItem=
$(".button").bind("mousedown",function(event){
$("#moveId").remove()
moveItem= $(this).clone();
moveItem.attr("id","moveId")
$("body").append(moveItem)
moveItem.css("left",event.clientX+2).css("top",event.clientY+2);
moveItem.css("opacity","0.5").css("position","fixed").css("point-events","none");
})
$("#con").bind("mouseup",function(event){
$(this).append(moveItem)
moveItem.css("opacity","1").css("position","static");
moveItem.attr("id","")
moveItem.css("display","inline-block");
})

$(document).bind("mousemove",function(event){
moveItem.css("left",event.clientX+2).css("top",event.clientY+2);
})
$(document).bind("mouseup",function(event){
$("#moveId").remove()
})
</script>
</body>
</html>






































以上是关于拖拽示例的主要内容,如果未能解决你的问题,请参考以下文章

Java 后台接口实现同级拖拽排序代码示例

JS—实现拖拽

react-dnd 拖拽

table表格列顺序拖拽和列宽度拖拽

解决 vue.draggable 拖拽 点击事件失效无效与拖拽事件冲突的问题

js学习笔记28----拖拽