<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>无标题文档</title>
<style>
#Drigging {
width:200px;
background:#CCC;
border:solid 1px #666;
height:80px;
line-height:80px;
text-align:center;
position:absolute;
}
</style>
<script src=
"jquery-1.8.2.min.js"
type=
"text/javascript"
></script>
<script type=
"text/javascript"
>
$(
function
(){
var
bool=false;
var
offsetX=0;
var
offsetY=0;
$(
"#Drigging"
).mouseover(
function
(){
$(this).css(
'cursor'
,
'move'
);
})
$(
"#Drigging"
).mousedown(
function
(){
bool=true;
offsetX = event.offsetX;
offsetY = event.offsetY;
$(this).css(
'cursor'
,
'move'
);
}).mouseup(
function
(){
bool=false;
})
$(document).mousemove(
function
(){
if
(!bool)
return
;
var
x = event.clientX-offsetX;
var
y = event.clientY-offsetY;
$(
"#Drigging"
).css(
"left"
, x);
$(
"#Drigging"
).css(
"top"
, y);
$(
"#Drigging"
).css(
'cursor'
,
'move'
);
})
})
</script>
</head>
<body>
<div id=
"Drigging"
style=
"float:left"
>
拖拽层
</div>
</body>
</html>