Writing JavaScript code to implement drag requires a lot of inconvenient maintenance code, which is really troublesome. Google has found an excellent Jquery plug-in EasyDrag for a long time. You only need a line of code to easily use it in mainstream browsers.
To achieve the drag effect.
$ (Document). ready (function ()
{
$ ("# DivPanel"). easydrag ();
}
);
Html code
<Div id = "divPanel" style = "width: 300px; height: 300px; background: white; border: 1px solid #000000; position: absolute; left: 5px; top: 50px ">
<Div id = "divTitle" style = "width: 100%; height: 25px; background: lavender">
& Nbsp; Title
</Div>
<Div style = "width: 100%">
</Div>
</Div>
EasyDrag can also specify the area that can be dragged. For example, you can only drag the entire div by using the title. JS can write
$ (Document). ready (function ()
{
$ ("# DivPanel"). easydrag ();
$ ("# DivPanel"). setHandler ("divTitle ");
}
);
One setHandler is done. Good open source is a good thing, Jquery is a good thing, and the plug-in extension mechanism is not very good.