| 1 | <!doctype html> |
| 2 | <html lang="en"> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 6 | <title>jQuery UI Draggable - Events</title> |
| 7 | <link rel="stylesheet" href="../../themes/base/all.css"> |
| 8 | <link rel="stylesheet" href="../demos.css"> |
| 9 | <style> |
| 10 | #draggable { width: 16em; padding: 0 1em; } |
| 11 | #draggable ul li { margin: 1em 0; padding: 0.5em 0; } * html #draggable ul li { height: 1%; } |
| 12 | #draggable ul li span.ui-icon { float: left; } |
| 13 | #draggable ul li span.count { font-weight: bold; } |
| 14 | </style> |
| 15 | <script src="../../external/requirejs/require.js"></script> |
| 16 | <script src="../bootstrap.js"> |
| 17 | var $start_counter = $( "#event-start" ), |
| 18 | $drag_counter = $( "#event-drag" ), |
| 19 | $stop_counter = $( "#event-stop" ), |
| 20 | counts = [ 0, 0, 0 ]; |
| 21 | |
| 22 | $( "#draggable" ).draggable({ |
| 23 | start: function() { |
| 24 | counts[ 0 ]++; |
| 25 | updateCounterStatus( $start_counter, counts[ 0 ] ); |
| 26 | }, |
| 27 | drag: function() { |
| 28 | counts[ 1 ]++; |
| 29 | updateCounterStatus( $drag_counter, counts[ 1 ] ); |
| 30 | }, |
| 31 | stop: function() { |
| 32 | counts[ 2 ]++; |
| 33 | updateCounterStatus( $stop_counter, counts[ 2 ] ); |
| 34 | } |
| 35 | }); |
| 36 | |
| 37 | function updateCounterStatus( $event_counter, new_count ) { |
| 38 | // first update the status visually... |
| 39 | if ( !$event_counter.hasClass( "ui-state-hover" ) ) { |
| 40 | $event_counter.addClass( "ui-state-hover" ) |
| 41 | .siblings().removeClass( "ui-state-hover" ); |
| 42 | } |
| 43 | // ...then update the numbers |
| 44 | $( "span.count", $event_counter ).text( new_count ); |
| 45 | } |
| 46 | </script> |
| 47 | </head> |
| 48 | <body> |
| 49 | |
| 50 | <div id="draggable" class="ui-widget ui-widget-content"> |
| 51 | |
| 52 | <p>Drag me to trigger the chain of events.</p> |
| 53 | |
| 54 | <ul class="ui-helper-reset"> |
| 55 | <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> |
| 56 | <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> |
| 57 | <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> |
| 58 | </ul> |
| 59 | </div> |
| 60 | |
| 61 | <div class="demo-description"> |
| 62 | <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> |
| 63 | </div> |
| 64 | </body> |
| 65 | </html> |