jquery draggable enable and disable

后端 未结 5 2054
耶瑟儿~
耶瑟儿~ 2020-12-30 05:43

Ive tried anything to do this, but always get the same error

$(\".tooltip\").draggable(\'disable\');

Error: cannot call methods on draggabl

相关标签:
5条回答
  • 2020-12-30 06:06

    I was able to recreate your scenario in this jsfiddle:

    http://jsfiddle.net/dboots/NDZKY/

    This is using

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

    and

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

    Is there something different that you're not able to do the same? Looks like you have the same syntax.

    0 讨论(0)
  • 2020-12-30 06:08

    Use one button to enable and disable

    $("#container").draggable({disabled:false});
    $("#container").draggable({disabled:true});
    

    Simple Example Given Below:

    <div id = "container"></div>
    <button id = "control"></button>
    <script>
      $(document).ready(function()
        {
           $("#control").click(function()
              {
                if($("#control").hasClass("active")
                  {
                    $("container").draggable({disabled:true});
                    $("control").removeAttr("class","active");   
                  }
                else
                  {
                    $("container").draggable({disabled:false});
                    $("control").attr("class","active");
                  }
              });
        });
    </script> 
    
    0 讨论(0)
  • 2020-12-30 06:09

    Take a look at the documentation http://api.jqueryui.com/draggable/

    and a example here:

    http://jqueryui.com/draggable/
    

    Have you "included" jquery-ui.js library?

    try on this fiddle! http://jsfiddle.net/3Lrg2/23/

    0 讨论(0)
  • 2020-12-30 06:18

    Try this:

    $(".tooltip").draggable({ disabled: true });
    

    This initializes the draggable in the disabled state. You can then use

    $(".tooltip").draggable("enable");
    

    later when you want to allow dragging.

    0 讨论(0)
  • 2020-12-30 06:26

    try using .unbind('ondrag') to remove the event from your element.

    sorry I think it should be $("tooltip").unbind('draggable') not 100% sure on event name.

    0 讨论(0)
提交回复
热议问题