DragClass.js[/code=JScript]
/*
Auth: jingliangliang
Date: 2008-5-5
Email: [email protected]
*/
(function(){
if(typeof Drag != "undefined")
{
var _Drag = Drag;
}
//此处声明Drag类
//--elementid:要移动元素的ID
var Drag = window.Drag = function(elementid){
var thisDrag = this;
this.DifWidth = 0;
this.DifHeight = 0;
this.thisDivDrag = document.getElementById(elementid);
this.thisDivDrag.onmousedown = function(event){
var theevent;
var theSrcevent;
if(window.event)
{
theevent = window.event;
theSrcevent = window.event.srcElement;
}
else
{
theevent =event;
theSrcevent =event.target;
}
thisDrag.DifWidth= theevent.clientX - theSrcevent.offsetLeft;
thisDrag.DifHeight = theevent.clientY - theSrcevent.offsetTop;
document.body.onmousemove =function(event){
var theevent;
if(window.event)
{
theevent = window.event;
}
else
{
theevent =event;
}
thisDrag.thisDivDrag.style.left = theevent.clientX -thisDrag.DifWidth ;
thisDrag.thisDivDrag.style.top = theevent.clientY -thisDrag.DifHeight ;
};
document.body.onmouseup =function(event)
{
document.body.onmousemove = "";
};
};
};
})();
[/code]--调用<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <script type="text/javascript" src="DragClass.js"></script>
  <script type="text/javascript">
window.onload=function(){
__Drag = new Drag("div1");
};
  </script>
 </HEAD> <BODY>
  <div id="div1" style="background-color:red;width:100px;height:100px;border:1px solid #666666;position: absolute;">test</div>
 </BODY>
</HTML>

解决方案 »

  1.   

    DragClass.js  
    /* 
    Auth: jingliangliang 
    Date: 2008-5-5 
    Email: [email protected] 
    */ 
    (function(){ 
    if(typeof Drag != "undefined") 

    var _Drag = Drag; 

    //此处声明Drag类 
    //--elementid:要移动元素的ID 
    var Drag = window.Drag = function(elementid){ 
    var thisDrag = this; 
    this.DifWidth = 0; 
    this.DifHeight = 0; 
    this.thisDivDrag = document.getElementById(elementid); 
    this.thisDivDrag.onmousedown = function(event){ 
    var theevent; 
    var theSrcevent; 
    if(window.event) 

    theevent = window.event; 
    theSrcevent = window.event.srcElement; 

    else 

    theevent =event; 
    theSrcevent =event.target; 

    thisDrag.DifWidth= theevent.clientX - theSrcevent.offsetLeft; 
    thisDrag.DifHeight = theevent.clientY - theSrcevent.offsetTop;
    document.body.onmousemove =function(event){ 
    var theevent;
    if(window.event) 

    theevent = window.event;

    else 

    theevent =event; 

    thisDrag.thisDivDrag.style.left = theevent.clientX -thisDrag.DifWidth ; 
    thisDrag.thisDivDrag.style.top = theevent.clientY -thisDrag.DifHeight ; 
    }; 
    document.body.onmouseup =function(event) 

    document.body.onmousemove = ""; 
    }; 
    }; 
    }; 
    })(); 
     
      

  2.   


    要想什么拖动,直接传入ID就可以了。例如你的文章,直接传送文章所在的ID就可以使文章可以拖动啊
      

  3.   

    9494 还要设置position是绝对。
      

  4.   

    其实我想要的就是CSDN的效果,比如你想回帖,然后点击那个登陆,弹出窗口,标题部分用于拖动整个层,
    然后下面的输入框可以输入,内容都可以全选,不用于拖动就这样
      

  5.   

    我有个示例要的话可以给你
    [email protected]