下面的代码为什么布恩那个实现层的拖动<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>
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>
解决方案 »
- Struts2 json extjs4也可谈谈大家经验,新人望指教(在线等),两帖子分数一共100
- 问个xmlhttprequest的回调函数的问题。
- js有没比较好的案例,实战书籍。
- jquery放大镜插件源图片过小问题
- Javascript问题,下面这个IFrame节点,如果用JavaScript动态创建,应该怎么写?
- 急~~!!如何通过子窗口父窗口创建div,并添加onclick事件?
- 请问一个颜色的小问题.新手,求救!!各位大哥!
- iframe问题
- 如何做到当秒数=5时,浏览器第一行写出时间,当秒数=15时,浏览器第二行写出时间
- 代码如下:我要从下拉列表中获取value值后判断是否相等这样怎么不行啊?求大神指教下呗,先谢谢了
- javascript数组的区别
- extjs3中gridpanel怎么实现末行数据合计功能
<!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>楼主 试试