Js drag div when the mouse moves the entire div also corresponds to the moving _ javascript skills

Source: Internet
Author: User
The div to be dragged is the outermost div. This Code binds the mouse listener event to the header of the displayed dialog box. When the mouse moves, the entire div is also moved as follows, if you are interested, refer to the following HTML code, where the p to be dragged is the outermost p

The Code is as follows:





Create user group






Group Name







User









Description










Confirm
Cancel



The js Code is as follows,

The Code is as follows:


$ ("# McreateUserGroup"). mousedown (function (e ){
Var flag = true;
E = e | event;
Var $ dialog_createUserGroup = $ ("# dialog_createUserGroup ");
Var LEFT = e. clientX-parseint(includialog_createusergroup.css ("left ")),
TOP = e. clientY-parseint(includialog_createusergroup.css ("top "));
$ (Document). mousemove (function (e ){
E = e | event;
If (flag ){
$Dialog_createUserGroup.css ({
"Left": e. clientX-LEFT + "px ",
"Top": e. clientY-TOP + "px"
});
}
});
$ (Document). mouseup (function (e ){
Flag = false;
});
});


This code binds the mouse listening event to the header of the displayed dialog box. When the mouse moves, the entire p moves accordingly!

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.