拖拽示例

<!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>

猜你喜欢

转载自www.cnblogs.com/liuhao-web/p/10008854.html