标签:lang smo als def width stp center utf-8 charset
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>传统拖拽2</title>
<style type="text/css">
#dialog{
position: relative;
width: 200px;
top:50px;
left:100px;
}
#title{
width: 100%;
height:50px;
background:#D7DEF0;
line-height: 50px;
text-align: center;
cursor:move;
}
.content{
width: 100%;
height:200px;
background: #F0F0F0;
}
</style>
<script src="js/jquery-1.10.1.js"></script>
</head>
<body>
<div id="dialog" >
<div id="title"></div>
<div class="content"></div>
</div>
<script type="text/javascript">
$(function(){
var isMouseDown=false;
var lastPoint={};
//获取title,并绑定事件
$("#title").mousedown(function(e){
isMouseDown=true;
lastPoint.x=e.pageX;
lastPoint.y=e.pageY;
}).mousemove(function(e){
//获取dialog
if(isMouseDown){
var dialog=$("#dialog");
var targetX=parseInt(dialog.css("left"))+e.pageX-lastPoint.x;
var targetY=parseInt(dialog.css("top"))+e.pageY-lastPoint.y;
dialog.css("left",targetX+"px");
dialog.css("top",targetY+"px");
lastPoint.x=e.pageX;
lastPoint.y=e.pageY;
}
}).mouseup(function(){
isMouseDown=false;
lastPoint={};
})
});
</script>
</body>
</html>
标签:lang smo als def width stp center utf-8 charset
原文地址:https://www.cnblogs.com/xu991377264/p/8995605.html