js 移动限制
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
html,body{margin:0px; padding:0px; font-family:Georgia, "Times New Roman", Times, serif; font-size:12px;}
</style>
</head>
<body>
<div style="margin:50px;line-height:200px; text-align:center; width:300px; height:200px; border:1px solid #ff6600; font-size:25px; color:#990000;" id="actd"></div>
<script type="text/javascript">
var _obj;
function $GetInfo(o){
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
}
function $hitTest(obj,e){
obj=$GetInfo(obj);
var x=getClientXY(e).cx;
var y=getClientXY(e).cy;
if((x>=obj.left&&x<=obj.right)&&(y>=obj.top&&y<=obj.bottom))return true;
else return false;
}
function getClientXY(e){
e=e||event;
return {cx:e.clientX,cy:e.clientY};
}
document.onmousemove=function(e){
var obj = document.getElementById('actd');
obj.innerHTML = $hitTest(obj,e)
};
</script>
</body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
html,body{margin:0px; padding:0px; font-family:Georgia, "Times New Roman", Times, serif; font-size:12px;}
</style>
</head>
<body>
<div style="margin:50px;line-height:200px; text-align:center; width:300px; height:200px; border:1px solid #ff6600; font-size:25px; color:#990000;" id="actd"></div>
<script type="text/javascript">
var _obj;
function $GetInfo(o){
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
}
function $hitTest(obj,e){
obj=$GetInfo(obj);
var x=getClientXY(e).cx;
var y=getClientXY(e).cy;
if((x>=obj.left&&x<=obj.right)&&(y>=obj.top&&y<=obj.bottom))return true;
else return false;
}
function getClientXY(e){
e=e||event;
return {cx:e.clientX,cy:e.clientY};
}
document.onmousemove=function(e){
var obj = document.getElementById('actd');
obj.innerHTML = $hitTest(obj,e)
};
</script>
</body>