Moving div is a very familiar thing for many people on the Internet. This article is a growing topic about how to move the div with a js mouse. I hope you can draw a line from each other, for more information, see. js:
The Code is as follows:
Var posX;
Var posY;
Fp = document. getElementById ("pBody ");
Document. getElementById ("pHead"). onmousedown = function (e)
{
If (! E) e = window. event; // IE
PosX = e. clientX-parseInt (fp. style. left );
PosY = e. clientY-parseInt (fp. style. top );
Document. onmousemove = mousemove;
}
Document. onmouseup = function ()
{
Document. onmousemove = null;
}
Function mousemove (ev)
{
If (ev = null) ev = window. event; // IE
Fp. style. left = (ev. clientX-posX) + "px ";
Fp. style. top = (ev. clientY-posY) + "px ";
}
Html:
The Code is as follows:
Css:
The Code is as follows:
. PBody {
// Margin-top: 20px;
Border: solid # CCC 1px;
Width: 500px;
Height: 400px;
Position: relative;
Z-index: 0;
Margin-left: auto;
Margin-right: auto;
}
. PHead {
Width: 500px;
Height: 50px;
Background-color: # CCC;
}
. Content
{
Width: 500px;
Height: 300px;
}
. Tail {
Background: # CCC;
Height: 50px;
Width: 500px;
Display: table-cell;
Vertical-align: middle;
}