拖拽示例
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>
以上是关于拖拽示例的主要内容,如果未能解决你的问题,请参考以下文章