单击启用和禁用jquery draggable containment

时间:2017-03-30 08:55:26

标签: jquery jquery-ui draggable jquery-ui-draggable

我创建了一个jquery可拖动的例子,

 <!DOCTYPE html>
<html>
<head>
  <style type="text/css">
.container{
    width:400px;
    height:200px;
    border:1px solid red;
}
#draggable{
    width: 100px;
    height: 50px;
}
  </style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script type="text/javascript">
    $( "#draggable" ).draggable({
    containment: ".container"
        });
  </script>
</head>
<body>
<div class="container">
    <div id="draggable" class="ui-widget-content">
        <p>Drag me around</p>
    </div>
</div>
<input type= "button" value="toggle containment" id="buttonContain">
</body>
</html>

其中,我可以在添加jquery drggable小部件后删除jquery draggable containment选项吗?请帮忙

1 个答案:

答案 0 :(得分:0)

您可以使用

 $("#draggable").draggable('disable'); 

表示禁用和

$("#draggable").draggable('enable'); 

启用按钮单击