web拖动Drag&Drop原理< html >
web拖动Drag&Drop原理
< head >
web拖动Drag&Drop原理
< title > Page Title </ title >
< style > ... .drag  {...} {
web拖动Drag&Drop原理     cursor
:  move ;
web拖动Drag&Drop原理
}
web拖动Drag&Drop原理
web拖动Drag&Drop原理
web拖动Drag&Drop原理
.box 
{...} {
web拖动Drag&Drop原理     margin
:  0px ;
web拖动Drag&Drop原理     width
:  200px ;
web拖动Drag&Drop原理     border
:  1px solid #ccc ;
web拖动Drag&Drop原理
}
.box h3.title 
{...} {
web拖动Drag&Drop原理     margin
:  0px ;
web拖动Drag&Drop原理     width
:  100% ;
web拖动Drag&Drop原理     background-color
:  #ccc ;
web拖动Drag&Drop原理
}
.box div.content 
{...} {
web拖动Drag&Drop原理     margin
:  0px ;
web拖动Drag&Drop原理     width
:  100% ;
web拖动Drag&Drop原理     text-align
:  left ;
web拖动Drag&Drop原理
}
web拖动Drag&Drop原理
</ style >
web拖动Drag&Drop原理
< script  type ="text/javascript" > ... // GreatGhoul
web拖动Drag&Drop原理 //
兼容ff, ie
web拖动Drag&Drop原理 //
要拖动的对象的title设置为'dragable'
web拖动Drag&Drop原理 //
拖动点的class设置为'drag',拖动点必须为可拖动对象的子节点
web拖动Drag&Drop原理

var  DragableObj  =   ...     handle:  null ,
web拖动Drag&Drop原理     dx: 
0 ,
web拖动Drag&Drop原理     dy: 
0 ,
web拖动Drag&Drop原理
    init: 
function (e)  ...         e  =  e  ||  event;
web拖动Drag&Drop原理         
this .handle  =  e.target  ||  e.srcElement;
web拖动Drag&Drop原理         
if  ( this .handle.className.indexOf( ' drag ' ==   - 1 return ;
         while  ( this .handle.tagName  !=   ' HTML '   &&   this .handle.title  !=   " dragable " ...
                        this .handle  =   this .handle.parentNode  ||   this .handle.parentElement;
web拖动Drag&Drop原理         }

web拖动Drag&Drop原理         
if  ( this .handle.title  !=   ' dragable ' return ;
web拖动Drag&Drop原理         
this .handle.style.position  =   ' relative ' ;
web拖动Drag&Drop原理         
this .dx  =  parseInt( this .handle.style.left  +   0 -  e.clientX;
web拖动Drag&Drop原理         
this .dy  =  parseInt( this .handle.style.top   +   0 -  e.clientY;
web拖动Drag&Drop原理         document.onmousemove 
=  DragableObj.drag;
web拖动Drag&Drop原理     }
,
    drag: 
function (e)  ...         e  =  e  ||  event;
        
if  ( this .handle  !=   null ...              this .handle.style.left  =  (e.clientX  +   this .dx)  +   ' px ' ;
web拖动Drag&Drop原理             
this .handle.style.top   =  (e.clientY  +   this .dy)  +   ' px ' ;
web拖动Drag&Drop原理         }

web拖动Drag&Drop原理     }
,
    drop: 
function (e)  ...          this .handle  =   null ;
web拖动Drag&Drop原理         document.onmousemove 
=   null ;
web拖动Drag&Drop原理     }

web拖动Drag&Drop原理 }
;
web拖动Drag&Drop原理 document.onmousedown 
=  DragableObj.init;
web拖动Drag&Drop原理 document.onmouseup   
=  DragableObj.drop;
document.onselectstart 
=   function (e)  ...     e  =  e  ||  event;
web拖动Drag&Drop原理     eo 
=  e.target  ||  event.srcElement;
web拖动Drag&Drop原理     
if  (eo.className.indexOf( ' drag ' !=   - 1 return   false ;
web拖动Drag&Drop原理 }
;
web拖动Drag&Drop原理
web拖动Drag&Drop原理
</ script >
web拖动Drag&Drop原理
</ head >
web拖动Drag&Drop原理
< body >
web拖动Drag&Drop原理
< br > 例1:
web拖动Drag&Drop原理
< div  class ="box"  title ="dragable" >
web拖动Drag&Drop原理
< h3  class ="drag title" >拖动标题 </ h3 >
web拖动Drag&Drop原理
< div  class ="content" >内容 </ div >
web拖动Drag&Drop原理
</ div >
web拖动Drag&Drop原理
web拖动Drag&Drop原理
< br > 例2:
web拖动Drag&Drop原理
< div  class ="drag"  title ="dragable" > 拖动我 </ div >
web拖动Drag&Drop原理
web拖动Drag&Drop原理
</ body >
web拖动Drag&Drop原理
</ html >
 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-01-02
  • 2022-01-01
  • 2021-06-01
  • 2022-12-23
猜你喜欢
  • 2021-05-26
  • 2021-12-22
  • 2017-11-23
  • 2022-12-23
  • 2022-01-27
相关资源
相似解决方案