- // JavaScript Document
- /////Created By RexLee//////////
- ///////function/////////////////
- function dragwin(div){
- var IsmouseDown;
- function mdown()
- {
- IsmouseDown=1;//全局变量
- x1=event.clientX;//全局变量x1
- y1=event.clientY;//全局变量y1
- x2=x1;//全局变量x2
- y2=y1;//全局变量y2
- }
- function mup()
- {
- IsmouseDown=0;
- }
- function dragit()
- {
- if(1==IsmouseDown)
- {
- x1=x2;
- y1=y2;
- x2=event.clientX;
- y2=event.clientY;
- var mx,my;
- mx=x2-x1;
- my=y2-y1;
- var xn=parseInt($("#"+div).CSS("left"),10);//parseInt(str,n)
- var yn=parseInt($("#"+div).css("top"),10);
- $("#"+div).css("left",xn+mx);
- $("#"+div).css("top",yn+my);
- }
- }
- ////////////////////////////////
- document.getElementById(div).onmousedown=mdown;
- document.getElementById(div).onmouseup=mup;
- document.getElementById(div).onmousemove=dragit;
- }
- dragwin("win");
- //该片段来自于http://www.codesnippet.cn/detail/110120131576.html
来源: http://www.codesnippet.cn/detail/110120131576.html