大鱼

js 最短拖动层div代码


 var drag_=false
var D=new Function('obj','return document.getElementById(obj);')
var oevent=new Function('e','if (!e) e = window.event;return e')
function Move_obj(obj){
 var x,y;
 D(obj).onmousedown=function(e){
  drag_=true;
  with(this){
   style.position="absolute";
   var temp1=offsetLeft;
   var temp2=offsetTop;
   x=oevent(e).clientX;
   y=oevent(e).clientY;
   document.onmousemove=function(e){
    if(!drag_)return false;
    with(this){
     style.left=temp1+oevent(e).clientX-x+"px";
     style.top=temp2+oevent(e).clientY-y+"px";
    }
   }
  }
  document.onmouseup=new Function("drag_=false");
 }
}

<div align="center" id="mess" onmouseover="Move_obj('mess')"></div>

posted on 2009-04-07 15:37 大鱼 阅读(328) 评论(0)  编辑  收藏 所属分类: javascript


只有注册用户登录后才能发表评论。


网站导航: