|
1 <!DOCTYPE html> |
|
2 <html lang="en"> |
|
3 <head> |
|
4 <meta charset="UTF-8" /> |
|
5 <title>jQuery UI Draggable - Events</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 <link type="text/css" href="../demos.css" rel="stylesheet" /> |
|
13 <style type="text/css"> |
|
14 #draggable { width: 16em; padding: 0 1em; } |
|
15 #draggable ul li { margin: 1em 0; padding: 0.5em 0; } * html #draggable ul li { height: 1%; } |
|
16 #draggable ul li span.ui-icon { float: left; } |
|
17 #draggable ul li span.count { font-weight: bold; } |
|
18 </style> |
|
19 <script type="text/javascript"> |
|
20 $(function() { |
|
21 var $start_counter = $('#event-start'), $drag_counter = $('#event-drag'), $stop_counter = $('#event-stop'); |
|
22 var counts = [0,0,0]; |
|
23 |
|
24 $("#draggable").draggable({ |
|
25 start: function() { |
|
26 counts[0]++; |
|
27 updateCounterStatus($start_counter,counts[0]); |
|
28 }, |
|
29 drag: function() { |
|
30 counts[1]++; |
|
31 updateCounterStatus($drag_counter,counts[1]); |
|
32 }, |
|
33 stop: function() { |
|
34 counts[2]++; |
|
35 updateCounterStatus($stop_counter,counts[2]); |
|
36 } |
|
37 }); |
|
38 }); |
|
39 |
|
40 function updateCounterStatus($event_counter,new_count) { |
|
41 // first update the status visually... |
|
42 if (!$event_counter.hasClass('ui-state-hover')) { |
|
43 $event_counter.addClass('ui-state-hover') |
|
44 .siblings().removeClass('ui-state-hover'); |
|
45 } |
|
46 // ...then update the numbers |
|
47 $('span.count',$event_counter).text(new_count); |
|
48 } |
|
49 </script> |
|
50 </head> |
|
51 <body> |
|
52 |
|
53 <div class="demo"> |
|
54 |
|
55 <div id="draggable" class="ui-widget ui-widget-content"> |
|
56 |
|
57 <p>Drag me to trigger the chain of events.</p> |
|
58 |
|
59 <ul class="ui-helper-reset"> |
|
60 <li id="event-start" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-play"></span>"start" invoked <span class="count">0</span>x</li> |
|
61 <li id="event-drag" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-arrow-4"></span>"drag" invoked <span class="count">0</span>x</li> |
|
62 <li id="event-stop" class="ui-state-default ui-corner-all"><span class="ui-icon ui-icon-stop"></span>"stop" invoked <span class="count">0</span>x</li> |
|
63 </ul> |
|
64 </div> |
|
65 |
|
66 </div><!-- End demo --> |
|
67 |
|
68 <div class="demo-description"> |
|
69 |
|
70 <p> |
|
71 Layer functionality onto the draggable using the <code>start</code>, <code>drag</code>, and <code>stop</code> events. Start is fired at the start of the drag; drag during the drag; and stop when dragging stops. |
|
72 </p> |
|
73 |
|
74 </div><!-- End demo-description --> |
|
75 |
|
76 </body> |
|
77 </html> |