1
|
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 type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" /> |
|
7 |
<script type="text/javascript" src="../../jquery-1.4.2.js"></script> |
|
8 |
<script type="text/javascript" src="../../ui/jquery.ui.core.js"></script> |
|
9 |
<script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script> |
|
10 |
<script type="text/javascript" src="../../ui/jquery.ui.mouse.js"></script> |
|
11 |
<script type="text/javascript" src="../../ui/jquery.ui.draggable.js"></script> |
|
12 |
<script type="text/javascript" src="../../ui/jquery.ui.droppable.js"></script> |
|
13 |
<link type="text/css" href="../demos.css" rel="stylesheet" /> |
|
14 |
<style type="text/css"> |
|
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 type="text/javascript"> |
|
19 |
$(function() { |
|
20 |
|
|
21 |
$("#draggable").draggable({ revert: 'valid' }); |
|
22 |
$("#draggable2").draggable({ revert: 'invalid' }); |
|
23 |
|
|
24 |
$("#droppable").droppable({ |
|
25 |
activeClass: 'ui-state-hover', |
|
26 |
hoverClass: 'ui-state-active', |
|
27 |
drop: function(event, ui) { |
|
28 |
$(this).addClass('ui-state-highlight').find('p').html('Dropped!'); |
|
29 |
} |
|
30 |
}); |
|
31 |
|
|
32 |
}); |
|
33 |
</script> |
|
34 |
</head> |
|
35 |
<body> |
|
36 |
<div class="demo"> |
|
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><!-- End demo --> |
|
51 |
|
|
52 |
<div class="demo-description"> |
|
53 |
|
|
54 |
<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> |
|
55 |
|
|
56 |
</div><!-- End demo-description --> |
|
57 |
</body> |
|
58 |
</html> |