本文实例讲述了jQuery实现的鼠标拖动画矩形框。分享给大家供大家参考,具体如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh" lang="zh">
<head>
<title>鼠标拖动画矩形</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<style type="text/css">
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td {margin: 0;padding: 0}
html {color: #000;overflow-y: scoll;overflow: -moz-scrollbars-vertical}
#confirmingAppraisal {
position: relative;
left: 0;
top: 0;
margin: 0 auto;
padding: 0;
width: 800px;
min-height: 800px;
overflow: auto;
height: 1000px;
background-color: #e9e9e9;
}
.dashed-box {position: absolute;z-index: 9997; border: 1px dashed red; width: 0px; height: 0px;left: 0px; top: 0px; overflow: hidden;}
#moving_box {background-color: #0A90DB;}
.question-box {
position: absolute;
z-index: 9998;
/*background: red;*/
/* older safari/Chrome browsers */
-webkit-opacity: 0.8;
/* Netscape and Older than Firefox 0.9 */
-moz-opacity: 0.8;
/* Safari 1.x (pre WebKit!) 老式khtml内核的Safari浏览器*/
-khtml-opacity: 0.8;
/* IE9 + etc...modern browsers */
opacity: .8;
/* IE 4-9 */
filter: alpha(opacity=80);
/*This works in IE 8 & 9 too*/
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
/*IE4-IE9*/
filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80);
}
.question-border {z-index: 9999;border: 2px dashed red;overflow: hidden; }
.del-box {
width: 17px;
height: 17px;
float: right;
position: relative;
margin-top: 1px;
margin-right: 1px;
z-index: 99999999999;
background: url(del.png);
}
</style>
<script language="javascript">
window.onload = function() {
function stopDefault(e) {
if(e && e.preventDefault)
e.preventDefault();
else
window.event.returnValue = false;
return false;
}
function oBox() {
var wId = "w";
var index = 0;
var target = null;
var startX = 0, startY = 0;
var flag = false;
var startL = 0, startT = 0, boxHeight = 0, boxWidth = 0;










