从51js论坛上路过时,看到别人贴的一段拖拽的JS代码,很简短就几行,除开在IE6内还有点小BUG外,在IE7、FF内均运行良好,固运用过来瞧瞧~~~
点击拖拽
代码如下:
<script type="text/javascript">
function Move(o, e){
var e = window.event || e;
var _xy = parseInt(o.offsetTop) - e.clientY;
var _xx = parseInt(o.offsetLeft) - e.clientX;
document.onmouseup = function(){
this.onmousemove = null;
}
if(e.preventDefault){
e.preventDefault();
}
document.onmousemove = function(e){
var e = window.event || e;
o.style.top = _xy + e.clientY + "px";
o.style.left = _xx + e.clientX + "px";
}
}
</script>
function Move(o, e){
var e = window.event || e;
var _xy = parseInt(o.offsetTop) - e.clientY;
var _xx = parseInt(o.offsetLeft) - e.clientX;
document.onmouseup = function(){
this.onmousemove = null;
}
if(e.preventDefault){
e.preventDefault();
}
document.onmousemove = function(e){
var e = window.event || e;
o.style.top = _xy + e.clientY + "px";
o.style.left = _xx + e.clientX + "px";
}
}
</script>