This example for everyone to demonstrate a relatively simple div drag, in addition to their own needs, add the corresponding code to achieve their desired effect, specific as follows, like please support under
This example is a very simple div drag, the need for friends can be based on their own needs, add the appropriate code. Welcome to the Brick
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
<html style= "height:100%;" >
<head>
<meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 ">
<title>div width resize</title>
<!--reference jquery-->
<script src= "Http://code.jquery.com/jquery-1.8.0.min.js"
type= "Text/javascript" ></script>
<script type= "Text/javascript" >
function Bindresize (EL)
{
//Initialization Parameters
var els = document.getElementById (' menu '). style;
//mouse X and Y axis coordinates
x = 0;
//Evil index finger
$ (EL). MouseDown (function (e)
{
//When the element is pressed, calculates the coordinates of the current mouse and object
x = e.clientx-el.offsetwidth-$ ("#menu"). width ();
//In support of setcapture to do some stuff
el.setcapture? (
//Capture Focus
el.setcapture (),
//Set event
el.onmousemove = function (EV)
{
mouseMove (EV | | | event);
},
el.onmouseup = mouseUp
) : (
//Binding event
$ (document). Bind ("MouseMove", MouseMove). Bind ("MouseUp", MouseUp)
);
//Prevent default events from occurring
E.preventdefault ();
});
//Mobile event
function MouseMove (e)
{
//Universe Super Invincible operation ...
els.width = e.clientx-x + ' px ';
}
//Stop event
function mouseUp ()
{
In support of releasecapture do some stuff
el.releasecapture? (
//Release Focus
el.releasecapture (),
//Removal event
El.onmousemove = El.onmouseup = null
) : (
//Uninstall Event
$ (document). Unbind ("MouseMove", MouseMove). Unbind ("MouseUp", MouseUp)
);
}
}
var divresize=function () {
var totalheight=$ ("html"). Height ();
Console.log (totalheight);
var topheight=$ ("#top"). Height ()
$ ("#menu"). Height (totalheight-topheight);
$ ("#rightbar"). Height (totalheight-topheight);
}
$ (function () {
divresize ();
$ (window). Resize (divresize);
bindresize (document.getElementById (' Rightbar '));
});
</script>
<style type= "Text/css" >
. Content {
width:200px;
background: #f1f1f1;
Text-align:center;
Border-color: #CCCCCC;
Border-style:solid;
border-width:0 1px;
}
</style>
</head>
<body style= "padding:0; margin:0; " >
<%--
<table style= "height:100%" >
<tr>
<td id= "menu" class= "Content" ></td>
<td id= "Rightbar"
style= "WIDTH:2PX; Background: #cccccc; Cursor:e-resize; " ></td>
</tr>
</table>
--%>
<div>
<div id= "Top" style= "width:100%; height:80px; " ></div>
<div style= "Float:left" id= "menu" class= "Content" >
<span> div</span>
to be dragged
</div>
<div id= "Rightbar"
style= "WIDTH:2PX; Background: #cccccc; Cursor:e-resize; Float:left; " ></div>
</div>
</body>
</html>