[转自横渡博客]鼠标拖动

< div id = " divMove "  style = " POSITION: absolute;left:300;top:300 "  onselectstart = " return false "  onmousedown = " MouseDown(this) "  onmousemove = " MouseMove() " >
        
< table width = " 150 "  cellpadding = " 0 "  cellspacing = " 0 "  border = " 1 " >
            
< tr >
                
< td height = " 30 "  bgcolor = " #cccccc " > title </ td >
            
</ tr >
            
< tr >
                
< td height = " 100 " >< p align = " center " > testMove </ p ></ td >
            
</ tr >
        
</ table >
    
</ div >
    
< SCRIPT LANGUAGE = " JavaScript " >
        
<!--
            
var  currentMoveObj  =   null ;
            
var  relLeft,relTop;
            
function  MouseDown(obj)
            {
                currentMoveObj 
=  obj;
                currentMoveObj.style.position 
=   " absolute " ;
                relLeft 
=  event.x  -  currentMoveObj.style.pixelLeft;
                relTop 
=  event.y  -  currentMoveObj.style.pixelTop;
            }
            window.document.onmouseup 
=   function ()
            {
                currentMoveObj 
=   null ;
            }
            
function  MouseMove()
            {
                
if (currentMoveObj  !=   null )
                {
                    currentMoveObj.style.pixelLeft
= event.x - relLeft;
                    currentMoveObj.style.pixelTop
= event.y - relTop;
                }
            }

        
// -->
         </ SCRIPT >

你可能感兴趣的:(博客)