1.js Control
var msgtitle=document.createelement ("div");
Msgtitle.onmousedown=function (e) {
var ev1=e| | window.event;
Get the margin of an element
var left=msgbox.offsetleft;
var top=msgbox.offsettop;
Get the coordinates of the mouse
var X=ev1.clientx;
var Y=ev1.clienty;
var x3=x-left;
var y3=y-top;
When the mouse moves
Document.onmousemove=function (e) {
var ev2=e| | window.event;
Gets the coordinates after the mouse move
var X2=ev2.clientx;
var Y2=ev2.clienty;
Calculate the new coordinates of the element
var newleft=x2-x3;
var newtop=y2-y3;
Limit boundaries
if (newleft<=0) {newleft=-(msgbox.offsetwidth*0)}
if (newtop<=0) {newtop=0};
msgbox.style.left=newleft+ "px";
msgbox.style.top=newtop+ "px";
};
Document.onmouseup=function () {
Document.onmousemove=null;
Document.onmouseup=null;
}
}
2.jQuery Control
var logintitle=$ ("<div></div>");
Form Move Event
Logintitle.mousedown (function (e) {
var ev=e| | window.event;
Get the margins of an element
var loginx=login.offset (). Left;
var loginy=login.offset (). Top;
Get the coordinates of the mouse click
var Monsex=ev.clientx;
var Monsey=ev.clienty;
Calculates the difference between the coordinate of an element and the mouse
var chax=parsefloat (monsex)-parsefloat (LoginX);
var chay=parsefloat (MonseY)-parsefloat (loginy);
Document.onmousemove=function (e) {
var ev2=e| | window.event;
Gets the coordinates after the mouse move
var X2=ev2.clientx;
var Y2=ev2.clienty;
Calculate the new coordinates of the element
var Newleft=x2-chax;
var Newtop=y2-chay;
Limit boundaries
if (newleft<=0) {newleft=0}
if (newtop<=0) {newtop=0};
Login.css ({"Top": newtop+ "px", "left": newleft+ "px"});
};
Document.onmouseup=function () {
Document.onmousemove=null;
Document.onmouseup=null;
}
});
Code space Project--window movement