<style>
.drag{position:relative;cursor:hand}
</style>
<script language="JavaScript">
var dragapproved=false
var eventsource,x,y
function move()
 {
  if (event.button==1&&dragapproved) //改变被拖动元素在页面上的位置
   {
    eventsource.style.pixelLeft=temp1+event.clientX-x
    eventsource.style.pixelTop=temp2+event.clientY-y
    return false
   }
 }
function drags()
 {
  if (!document.all)
  return
  if (event.srcElement.className=="drag") //捕捉鼠标和被拖动元素的当前位置
   {
    dragapproved=true
    eventsource=event.srcElement
    temp1=eventsource.style.pixelLeft
    temp2=eventsource.style.pixelTop
    x=event.clientX
    y=event.clientY
    document.onmousemove=move
   }
 }
document.onmousedown=drags   //鼠标左键按下时,准备拖动
document.onmouseup=new Function("dragapproved=false")//鼠标左键放开时,拖动停止
</script>
<span style="font-family:DextorOutD;font-size: 9pt">
<div id=mydiv class=drag style="background:red;width:50%">
<p>drag it!</p>
<p align=center><input type=button value=drag><p>
<p>ha ha!</p>
</div>
</span>

解决方案 »

  1.   

    to : seabell(百合心)
        
         拖动的不够流畅,有没有更好的?
      

  2.   

    觉得很流畅啊,将中间的button换掉看看
    <style>
    .drag{position:relative;cursor:hand}
    </style>
    <script language="JavaScript">
    var dragapproved=false
    var eventsource,x,y
    function move()
     {
      if (event.button==1&&dragapproved) //改变被拖动元素在页面上的位置
       {
        eventsource.style.pixelLeft=temp1+event.clientX-x
        eventsource.style.pixelTop=temp2+event.clientY-y
        return false
       }
     }
    function drags()
     {
      if (!document.all)
      return
      if (event.srcElement.className=="drag") //捕捉鼠标和被拖动元素的当前位置
       {
        dragapproved=true
        eventsource=event.srcElement
        temp1=eventsource.style.pixelLeft
        temp2=eventsource.style.pixelTop
        x=event.clientX
        y=event.clientY
        document.onmousemove=move
       }
     }
    document.onmousedown=drags   //鼠标左键按下时,准备拖动
    document.onmouseup=new Function("dragapproved=false")//鼠标左键放开时,拖动停止
    </script>
    <span style="font-family:DextorOutD;font-size: 9pt">
    <div id=mydiv class=drag style="background:red;width:50%">
    <p>drag it!</p>
    <p align=center>text<p>
    <p>ha ha!</p>
    </div>
    </span>
      

  3.   

    我这里有个例子,你看看吗?把信箱留下。
    我的是[email protected]
      

  4.   

    window.event.srcElement.setCapture();
    window.event.srcElement.releaseCapture();
      

  5.   

    to: qiushuiwuhen(秋水无恨) 
        帮忙放个例子吧
      

  6.   

    http://www.webucn.com/zz/nbw_v3/看这个窗口拖动,十分流畅,有一个关键的问题就是秋水用上面的方法解决的。过程这样:onmousedown时,获取鼠标在屏幕上的位置,同时setCapture(),onmouseup时,releaseCapture();。关键的过程在于onmousemove,首先判断event.button是否等于1,不等于,返回;如果等于,即时判断鼠标当前位置,然后要得出与onmousedown时的差值,窗口的实际位置加上这个差值重新定位。
      

  7.   

    我现在只想单击锁定,因为鼠标移动到iframe里面就不能响应各种事件,如何做啊
      

  8.   

    楼主:试试这个
    <style>
    .drag{position:relative;cursor:hand}
    </style>
    <script language="JavaScript">
    var dragapproved=false
    var eventsource,x,y
    function move()
     {
      if (dragapproved) //改变被拖动元素在页面上的位置
       {
        eventsource.style.pixelLeft=temp1+event.clientX-x
        eventsource.style.pixelTop=temp2+event.clientY-y
        return false
       }
     }
    function drags()
     {
      if (!document.all)
      return
      if (event.srcElement.className=="drag") //捕捉鼠标和被拖动元素的当前位置
       {
        dragapproved=true
        eventsource=event.srcElement
        temp1=eventsource.style.pixelLeft
        temp2=eventsource.style.pixelTop
        x=event.clientX
        y=event.clientY
        document.onmousemove=move
       }
     }
    document.onmousedown=drags   //鼠标左键按下时,准备拖动
    document.onmouseup=new Function("dragapproved=!dragapproved")//鼠标左键放开时,拖动停止
    </script>
    <span style="font-family:DextorOutD;font-size: 9pt">
    <input type=button value="drag me" class=drag>
    </span>
      

  9.   

    有没有人做一个类似Windows里面的拖动窗口不显示窗口内容啊...
    呵呵,先用一个虚框代替实际的层...那样速度绝对流畅.