1 |
<!doctype html> |
2 |
<html lang="en"> |
3 |
<head> |
4 |
<meta charset="utf-8"> |
5 |
<title>jQuery UI Droppable - Revert draggable position</title> |
6 |
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css"> |
7 |
<script src="../../jquery-1.9.1.js"></script> |
8 |
<script src="../../ui/jquery.ui.core.js"></script> |
9 |
<script src="../../ui/jquery.ui.widget.js"></script> |
10 |
<script src="../../ui/jquery.ui.mouse.js"></script> |
11 |
<script src="../../ui/jquery.ui.draggable.js"></script> |
12 |
<script src="../../ui/jquery.ui.droppable.js"></script> |
13 |
<link rel="stylesheet" href="../demos.css"> |
14 |
<style> |
15 |
#draggable, #draggable2 { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; } |
16 |
#droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; } |
17 |
</style> |
18 |
<script> |
19 |
$(function() { |
20 |
$( "#draggable" ).draggable({ revert: "valid" }); |
21 |
$( "#draggable2" ).draggable({ revert: "invalid" }); |
22 |
|
23 |
$( "#droppable" ).droppable({ |
24 |
activeClass: "ui-state-hover", |
25 |
hoverClass: "ui-state-active", |
26 |
drop: function( event, ui ) { |
27 |
$( this ) |
28 |
.addClass( "ui-state-highlight" ) |
29 |
.find( "p" ) |
30 |
.html( "Dropped!" ); |
31 |
} |
32 |
}); |
33 |
}); |
34 |
</script> |
35 |
</head> |
36 |
<body> |
37 |
|
38 |
<div id="draggable" class="ui-widget-content"> |
39 |
<p>I revert when I'm dropped</p> |
40 |
</div> |
41 |
|
42 |
<div id="draggable2" class="ui-widget-content"> |
43 |
<p>I revert when I'm not dropped</p> |
44 |
</div> |
45 |
|
46 |
<div id="droppable" class="ui-widget-header"> |
47 |
<p>Drop me here</p> |
48 |
</div> |
49 |
|
50 |
<div class="demo-description"> |
51 |
<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> |
52 |
</div> |
53 |
</body> |
54 |
</html> |