【问题标题】:enable and disable jquery draggable containment on click单击时启用和禁用 jquery 可拖动包含
【发布时间】:2017-03-30 08:55:25
【问题描述】:

我已经创建了一个 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 可拖动包含选项吗?请帮忙

【问题讨论】:

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


    【解决方案1】:

    你可以使用

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

    用于禁用和

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

    点击按钮启用

    【讨论】:

    • 感谢您的回答@Sanyami Vaidya,但我想在单击按钮时切换可拖动的包含选项
    猜你喜欢
    • 2012-06-16
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多