Code space Project--window movement

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.