jquery draggable widget
jquery draggable widget allow elements to be moved using the mouse. This widget is in interactions category on the jQuery UI website.
http://jqueryui.com/draggable
Consider the following HTML
<div id="draggableDiv" class="divClass">
Drag me around
</div>
.divClass {
height: 200px;
width: 200px;
background-color: red;
color: white;
display: table-cell;
vertical-align: middle;
text-align: center;
}
To make the above div element draggable
$('#draggableDiv').draggable();
HTML
<div id="containerDiv" style="height: 300px; width: 300px; border: 3px solid black">
<div id="draggableDiv" class="divClass">
Drag me around
</div>
</div>
jQuery
$('#draggableDiv').draggable({
containment : 'parent'
});
Changes the cursor style to "move" during the drag operation
$('#draggableDiv').draggable({
cursor: 'move'
});
Changes the opacity to 0.3 during the drag operation
$('#draggableDiv').draggable({
opacity : 0.3
});
Reverts the div element to its start position when dragging stops. Revert animation completes in 1000 milli-seconds.
$('#draggableDiv').draggable({
revert: true,
revertDuration : 1000
});
The following example
1. Snaps the coloured div elements to the div element with thick black border.
2. The snapping occurs as soon as the distance between any of the coloured div element and the div element with thick black border is 50 pixels
3. The cancel option cancels dragging from starting on the div element with thick black border
HTML
<div id="redDiv" class="divClass" style="background-color: red">
Red Div
</div>
<div id="greeDiv" class="divClass" style="background-color: green">
Green Div
</div>
<div id="blueDiv" class="divClass" style="background-color: blue">
Blue Div
</div>
<div id="brownDiv" class="divClass" style="background-color: brown">
Brown Div
</div>
<br />
<br />
<div id="snapDiv" style="height: 400px; width: 400px; border: 5px solid black">
</div>
Style
.divClass {
height: 200px;
width: 200px;
background-color: red;
color: white;
display: table-cell;
vertical-align: middle;
text-align: center;
}
jQuery
$('div').draggable({
snap: '#snapDiv',
snapTolerance: 50,
cancel : '#snapDiv'
});
http://jqueryui.com/draggable
Consider the following HTML
<div id="draggableDiv" class="divClass">
Drag me around
</div>
.divClass {
height: 200px;
width: 200px;
background-color: red;
color: white;
display: table-cell;
vertical-align: middle;
text-align: center;
}
To make the above div element draggable
$('#draggableDiv').draggable();
HTML
<div id="containerDiv" style="height: 300px; width: 300px; border: 3px solid black">
<div id="draggableDiv" class="divClass">
Drag me around
</div>
</div>
jQuery
$('#draggableDiv').draggable({
containment : 'parent'
});
Changes the cursor style to "move" during the drag operation
$('#draggableDiv').draggable({
cursor: 'move'
});
Changes the opacity to 0.3 during the drag operation
$('#draggableDiv').draggable({
opacity : 0.3
});
Reverts the div element to its start position when dragging stops. Revert animation completes in 1000 milli-seconds.
$('#draggableDiv').draggable({
revert: true,
revertDuration : 1000
});
The following example
1. Snaps the coloured div elements to the div element with thick black border.
2. The snapping occurs as soon as the distance between any of the coloured div element and the div element with thick black border is 50 pixels
3. The cancel option cancels dragging from starting on the div element with thick black border
HTML
<div id="redDiv" class="divClass" style="background-color: red">
Red Div
</div>
<div id="greeDiv" class="divClass" style="background-color: green">
Green Div
</div>
<div id="blueDiv" class="divClass" style="background-color: blue">
Blue Div
</div>
<div id="brownDiv" class="divClass" style="background-color: brown">
Brown Div
</div>
<br />
<br />
<div id="snapDiv" style="height: 400px; width: 400px; border: 5px solid black">
</div>
Style
.divClass {
height: 200px;
width: 200px;
background-color: red;
color: white;
display: table-cell;
vertical-align: middle;
text-align: center;
}
jQuery
$('div').draggable({
snap: '#snapDiv',
snapTolerance: 50,
cancel : '#snapDiv'
});
Comments
Post a Comment