javascript 拖动出现异常 javascript移动异常鼠标 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <html> <head> <meta charset="utf-8"> <title>self</title> <script type="text/javascript" charset="utf-8"> var Drag = { obj:null, startX : 0, startY : 0, init:function(id){ var o = document.getElementById(id); o.onmousedown = Drag.start; }, start : function(e){ var o = Drag.obj = this; o.lastMouseX = Drag.getEvent(e).x; o.lastMouseY = Drag.getEvent(e).y; Drag.startX = o.style.left; Drag.startY = o.style.top; document.onmousemove = Drag.move; document.onmouseup = Drag.end; }, move : function(e){ var o = Drag.obj; var dx = Drag.getEvent(e).x - o.lastMouseX; var dy = Drag.getEvent(e).y - o.lastMouseY; var left = parseInt(o.style.left)+dx; var top = parseInt(o.style.top)+dy; o.style.left = left; o.style.top = top; o.lastMouseX = Drag.getEvent(e).x; o.lastMouseY = Drag.getEvent(e).y; }, end : function(e){ var o = Drag.obj; if(o.style.top != Drag.startY){ o.style.top = Drag.startY; } if(o.style.left != Drag.startX){ o.style.left = Drag.startX; } document.onMouseup = null; document.onmousemove = null; document.onmousedown = null; Drag.obj = null; }, getEvent : function(e){ if(typeof e =='undefined'){ e = window.event; } if(typeof e.x =='undefined'){ e.x = e.layerX; } if(typeof e.y == 'undefined'){ e.y = e.layerY; } return e; } } </script> </head> <body> <div id = "r" style="position: absolute;top:100px;left:100px;background-color: red;width: 100px;height: 100px;z-index: 10;"></div> <div id = "g" style="position: absolute;top:100px;left:250px;background-color: green;width: 100px;height: 100px;z-index: 10;"></div> <div id = "b" style="position: absolute;top:100px;left:400px;background-color: blue;width: 100px;height: 100px;z-index: 10;"></div> </body> <script type="text/javascript" charset="utf-8"> Drag.init('g'); Drag.init('r'); Drag.init('b'); </script></html> 图片向左滚动效果,为什么只有一张图片,却显示了两张 JS 如何判断 checkboxlist 没被选中(勾选) 问一个vbscript的问题,谢谢 iframe中的弹出式菜单,如何让它浮在最上层显示? 关于turnjs问题请教 请教高人,我想取得某个日期的4天前的日期,函数有吗? 如何让两个下拉表单从数据库里提出来的数据相关联? Select中的列表文字左边能否是复选框?up者有分 关于动态显示网页的问题 急救!!在线等待!!! JQ如何根据DATA取控件 学了jQuery以后还有必要再学JavaScript吗
<head>
<meta charset="utf-8">
<title>self</title>
<script type="text/javascript" charset="utf-8">
var Drag = {
obj:null,
startX : 0,
startY : 0,
init:function(id){
var o = document.getElementById(id);
o.onmousedown = Drag.start;
},
start : function(e){
var o = Drag.obj = this;
o.lastMouseX = Drag.getEvent(e).x;
o.lastMouseY = Drag.getEvent(e).y;
Drag.startX = o.style.left;
Drag.startY = o.style.top;
document.onmousemove = Drag.move;
document.onmouseup = Drag.end;
},
move : function(e){
var o = Drag.obj;
var dx = Drag.getEvent(e).x - o.lastMouseX;
var dy = Drag.getEvent(e).y - o.lastMouseY;
var left = parseInt(o.style.left)+dx;
var top = parseInt(o.style.top)+dy;
o.style.left = left;
o.style.top = top;
o.lastMouseX = Drag.getEvent(e).x;
o.lastMouseY = Drag.getEvent(e).y;
},
end : function(e){
var o = Drag.obj;
if(o.style.top != Drag.startY){
o.style.top = Drag.startY;
}
if(o.style.left != Drag.startX){
o.style.left = Drag.startX;
}
document.onMouseup = null;
document.onmousemove = null;
document.onmousedown = null;
Drag.obj = null;
},
getEvent : function(e){
if(typeof e =='undefined'){
e = window.event;
}
if(typeof e.x =='undefined'){
e.x = e.layerX;
}
if(typeof e.y == 'undefined'){
e.y = e.layerY;
}
return e;
}
}
</script>
</head>
<body>
<div id = "r" style="position: absolute;top:100px;left:100px;background-color: red;width: 100px;height: 100px;z-index: 10;"></div>
<div id = "g" style="position: absolute;top:100px;left:250px;background-color: green;width: 100px;height: 100px;z-index: 10;"></div>
<div id = "b" style="position: absolute;top:100px;left:400px;background-color: blue;width: 100px;height: 100px;z-index: 10;"></div>
</body>
<script type="text/javascript" charset="utf-8">
Drag.init('g');
Drag.init('r');
Drag.init('b');
</script>
</html>