Disable, enable and destroy the draggable object : UI Draggable « jQuery « JavaScript DHTML






Disable, enable and destroy the draggable object

 

<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
  <script type="text/javascript" src="js/ui/ui.core.js"></script>
  <script type="text/javascript" src="js/ui/ui.draggable.js"></script>
  <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        $("#drag").draggable();
        
        //define function to toggle draggability
        function toggle(action) {
          (action == "destroy") ? $("#drag").draggable(action).removeClass("drag") : $("#drag").draggable(action);   
        } 
          
        //define click handler for buttons
        $("button").click(function() {
          toggle($(this).attr("id"));
        });
    });
  </script>
</head>
<body>
    <button id="disable">Disable</button>
    <button id="enable">Enable</button>
    <button id="destroy">Destroy</button>
    <div id="drag">asdf</div>


</body>
</html>

   
  








Related examples in the same category

1.jQuery UI Draggable - Constrain movement
2.jQuery UI Draggable - Cursor style
3.jQuery UI Draggable - Default functionality
4.jQuery UI Draggable - Delay start
5.jQuery UI Draggable - Events
6.jQuery UI Draggable - Handles
7.jQuery UI Draggable - Revert position
8.jQuery UI Draggable - Auto-scroll
9.jQuery UI Draggable - Snap to element or grid
10.jQuery UI Draggable + Sortable
11.jQuery UI Draggable - Visual feedback
12.Change cursor for draggable tag
13.Set cursor position for the draggable
14.Can only drag along with axis y
15.Drag delay
16.Drag along a grid
17.Add border to the draggable
18.Only draggable inside parent
19.Add dragging stopped event handler
20.revert: true (fly back)
21.Snap to another
22.start and stop events
23.Set the handles for all directions
24.Add knobHandles