具体的原理我就不多说了,直接贴代码。
html代码:
<!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>
<title>Draw rectangle</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<script src=”jquery-1.6.2.min.js” type=”text/javascript”></script>
<script src=”jquery.ui.core.js” type=”text/javascript”></script>
<script src=”jquery.ui.widget.js” type=”text/javascript”></script>
<script src=”jquery.ui.mouse.js” type=”text/javascript”></script>
<script src=”jquery.ui.draggable.js” type=”text/javascript”></script>
<link href=”catch.css” rel=”stylesheet” type=”text/css”;charset=gb2312/>
<script src=”catch.js” type=”text/javascript”;charset=gb2312></script>
<!–[if gte IE 7]>
<style type=”text/css”>
</style>
<![endif]–>
</head>
<body>
<!– header –>
<div id=”header”>
<label>Draw!</label>
</div>
<!– content –>
<div id=”content”>
</div>
<!– bottom –>
<div id=”bottom”>
</div>
</body>
</html>
css代码:
body
{
font-family: “Helvetica Neue”, “Lucida Grande”, “Segoe UI”, Arial, Helvetica, Verdana, sans-serif;
margin: 0px;
}
#header
{
width:150px;
margin:0px auto;
}
#header label
{
font-size:45px;
font-weight:bolder;
}
#content
{
width:90%;
height:600px;
margin:10px auto;
border:1px solid blue;
}
.new_rect
{
opacity: 0.7;
-moz-opacity: 0.7;
filter: alpha(opacity=70);
-ms-filter: alpha(opacity=70);
background:#A8CAEC;
border:1px solid #3399FF;
position:fixed;
float:left;
}
.new_rect:hover{
cursor:move;
}
.mousedown{
-webkit-box-shadow:5px 5px 5px black;
-moz-box-shadow:5px 5px 5px black;
box-shadow:5px 5px 5px black;
z-index:999;
}
js代码:
//////////////////////////////////////////////////////////
$(function () {
//$(“div[title=new_rect]”).click(function(){alert(“click”);});
//$(“.new_rect”).draggable();
drow_rect(“#content”);
})
/////////////////////////////////////////////////////////
function drow_rect(the_id){//theid表示用作画布的层










