5 <title>jQuery UI Draggable - Events</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 <link rel="stylesheet" href="../demos.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; }
21 var $start_counter = $( "#event-start" ),
22 $drag_counter = $( "#event-drag" ),
23 $stop_counter = $( "#event-stop" ),
26 $( "#draggable" ).draggable({
29 updateCounterStatus( $start_counter, counts[ 0 ] );
33 updateCounterStatus( $drag_counter, counts[ 1 ] );
37 updateCounterStatus( $stop_counter, counts[ 2 ] );
41 function updateCounterStatus( $event_counter, new_count ) {
42 // first update the status visually...
43 if ( !$event_counter.hasClass( "ui-state-hover" ) ) {
44 $event_counter.addClass( "ui-state-hover" )
45 .siblings().removeClass( "ui-state-hover" );
47 // ...then update the numbers
48 $( "span.count", $event_counter ).text( new_count );
55 <div id="draggable" class="ui-widget ui-widget-content">
57 <p>Drag me to trigger the chain of events.</p>
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>
66 <div class="demo-description">
67 <p>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.</p>