87,990
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
function divdown(){
flag=true;
//o=document.getElementById("move");
//o.setCapture();
//alert(flag);
}
document.onmousemove=function(){
d=event;
window.status="X:"+event.clientX+" Y:"+event.clientY;
//if(!o)return;
if(flag){
a=document.getElementById("move");
b=event.clientX-parseInt(a.style.left);
c=event.clientY-parseInt(a.style.top);
a.style.left=(d.clientX-b)+"px";
a.style.top=(d.clientY-c)+"px";
//a.style.left=(event.clientX)+"px";
//a.style.top=(event.clientY)+"px";
}
}
function divup(){
flag=false;
//alert(flag);
}
function showdiv(){
var div=document.createElement("div");
div.id="move";
div.style.position="absolute";
div.style.backgroundColor="#f0f";
div.style.width=100+"px";
div.style.height=100+"px";
div.style.top=100+"px";
div.style.left=100+"px";
document.body.appendChild(div);
div.style.display="block";
div.onmousedown=divdown;
div.onmouseup=divup;
}
var a,b,c,flag=false,o;
</script>
</head>
<body>
<input id="btn" type="button" value="显示DIV" onclick="showdiv()"/>
</body>
<!doctype html>
<script type="text/javascript">
function divdown(){
flag=true;
//o=document.getElementById("move");
//o.setCapture();
//alert(flag);
}
document.onmousemove=function(event){
event = event || window.event;
window.status="X:"+event.clientX+" Y:"+event.clientY;
//if(!o)return;
if(flag){
a=document.getElementById("move");
b=parseInt(a.style.width)/2
c=parseInt(a.style.top)/2
a.style.left=(event.clientX-b)+"px";
a.style.top=(event.clientY-c)+"px";
// a.style.left=(event.clientX)+"px";
// a.style.top=(event.clientY)+"px";
}
}
function divup(){
flag=false;
//alert(flag);
}
function showdiv(){
var div=document.createElement("div");
div.id="move";
div.style.position="absolute";
div.style.backgroundColor="#f0f";
div.style.width=100+"px";
div.style.height=100+"px";
div.style.top=100+"px";
div.style.left=100+"px";
document.body.appendChild(div);
div.style.display="block";
div.onmousedown=divdown;
div.onmouseup=divup;
}
var a,b,c,flag=false,o;
</script>
</head>
<body>
<input id="btn" type="button" value="显示DIV" onclick="showdiv()"/>
<div id="test"></div>
</body>