0
|
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.5.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 class="demo">
|
|
39
|
|
40 <div id="draggable" class="ui-widget-content">
|
|
41 <p>I revert when I'm dropped</p>
|
|
42 </div>
|
|
43
|
|
44 <div id="draggable2" class="ui-widget-content">
|
|
45 <p>I revert when I'm not dropped</p>
|
|
46 </div>
|
|
47
|
|
48 <div id="droppable" class="ui-widget-header">
|
|
49 <p>Drop me here</p>
|
|
50 </div>
|
|
51
|
|
52 </div><!-- End demo -->
|
|
53
|
|
54
|
|
55
|
|
56 <div class="demo-description">
|
|
57 <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>
|
|
58 </div><!-- End demo-description -->
|
|
59
|
|
60 </body>
|
|
61 </html>
|