| 1 |
<!doctype html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 |
<title>jQuery UI Droppable - Revert draggable position</title> |
| 7 |
<link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 |
<link rel="stylesheet" href="../demos.css"> |
| 9 |
<style> |
| 10 |
#draggable, #draggable2 { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; } |
| 11 |
#droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; } |
| 12 |
</style> |
| 13 |
<script src="../../external/requirejs/require.js"></script> |
| 14 |
<script src="../bootstrap.js"> |
| 15 |
$( "#draggable" ).draggable({ revert: "valid" }); |
| 16 |
$( "#draggable2" ).draggable({ revert: "invalid" }); |
| 17 |
|
| 18 |
$( "#droppable" ).droppable({ |
| 19 |
classes: { |
| 20 |
"ui-droppable-active": "ui-state-active", |
| 21 |
"ui-droppable-hover": "ui-state-hover" |
| 22 |
}, |
| 23 |
drop: function( event, ui ) { |
| 24 |
$( this ) |
| 25 |
.addClass( "ui-state-highlight" ) |
| 26 |
.find( "p" ) |
| 27 |
.html( "Dropped!" ); |
| 28 |
} |
| 29 |
}); |
| 30 |
</script> |
| 31 |
</head> |
| 32 |
<body> |
| 33 |
|
| 34 |
<div id="draggable" class="ui-widget-content"> |
| 35 |
<p>I revert when I'm dropped</p> |
| 36 |
</div> |
| 37 |
|
| 38 |
<div id="draggable2" class="ui-widget-content"> |
| 39 |
<p>I revert when I'm not dropped</p> |
| 40 |
</div> |
| 41 |
|
| 42 |
<div id="droppable" class="ui-widget-header"> |
| 43 |
<p>Drop me here</p> |
| 44 |
</div> |
| 45 |
|
| 46 |
<div class="demo-description"> |
| 47 |
<p>Return the draggable (or it's helper) to its original location when dragging stops with the boolean <code>revert</code> option set on the draggable.</p> |
| 48 |
</div> |
| 49 |
</body> |
| 50 |
</html> |