1
|
1 |
<!DOCTYPE html> |
|
2 |
<html lang="en"> |
|
3 |
<head> |
|
4 |
<meta charset="UTF-8" /> |
|
5 |
<title>jQuery UI Droppable - Prevent propagation</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 { width: 100px; height: 40px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; } |
|
16 |
#droppable, #droppable2 { width: 230px; height: 120px; padding: 0.5em; float: left; margin: 10px; } |
|
17 |
#droppable-inner, #droppable2-inner { width: 170px; height: 60px; padding: 0.5em; float: left; margin: 10px; } |
|
18 |
</style> |
|
19 |
<script type="text/javascript"> |
|
20 |
$(function() { |
|
21 |
|
|
22 |
$("#draggable").draggable(); |
|
23 |
|
|
24 |
$("#droppable, #droppable-inner").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 |
return false; |
|
30 |
} |
|
31 |
}); |
|
32 |
|
|
33 |
$("#droppable2, #droppable2-inner").droppable({ |
|
34 |
greedy: true, |
|
35 |
activeClass: 'ui-state-hover', |
|
36 |
hoverClass: 'ui-state-active', |
|
37 |
drop: function(event, ui) { |
|
38 |
$(this).addClass('ui-state-highlight').find('> p').html('Dropped!'); |
|
39 |
} |
|
40 |
}); |
|
41 |
|
|
42 |
}); |
|
43 |
</script> |
|
44 |
</head> |
|
45 |
<body> |
|
46 |
<div class="demo"> |
|
47 |
|
|
48 |
<div id="draggable" class="ui-widget-content"> |
|
49 |
<p>Drag me to my target</p> |
|
50 |
</div> |
|
51 |
|
|
52 |
<div id="droppable" class="ui-widget-header"> |
|
53 |
<p>Outer droppable</p> |
|
54 |
<div id="droppable-inner" class="ui-widget-header"> |
|
55 |
<p>Inner droppable (not greedy)</p> |
|
56 |
</div> |
|
57 |
</div> |
|
58 |
|
|
59 |
<div id="droppable2" class="ui-widget-header"> |
|
60 |
<p>Outer droppable</p> |
|
61 |
<div id="droppable2-inner" class="ui-widget-header"> |
|
62 |
<p>Inner droppable (greedy)</p> |
|
63 |
</div> |
|
64 |
</div> |
|
65 |
|
|
66 |
</div><!-- End demo --> |
|
67 |
|
|
68 |
<div class="demo-description"> |
|
69 |
|
|
70 |
<p>When working with nested droppables — for example, you may have an editable directory structure displayed as a tree, with folder and document nodes — the <code>greedy</code> option set to true prevents event propagation when a draggable is dropped on a child node (droppable).</p> |
|
71 |
|
|
72 |
</div><!-- End demo-description --> |
|
73 |
</body> |
|
74 |
</html> |