开发者

Jquery Dragable help disabled when clicked

开发者 https://www.devze.com 2023-01-15 08:08 出处:网络
i am currently use Draggable in Jquery i am trying to make it so when you click on a div it will disable you from draging it i have the follow code be it seems to not work can anyone lead me in the ri

i am currently use Draggable in Jquery i am trying to make it so when you click on a div it will disable you from draging it i have the follow code be it seems to not work can anyone lead me in the right directio开发者_如何学Cn please

selected_div = $("input#selected_div").val();

 $("#68").draggable({ 
          containment: 'parent',
if(selected_div == 68){
          disabled: true,
}else{
          disabled: false,
}
          handle: 'drag_border',
          drag: function(e, ui) {
                 var top = ui.position.top;
                 var left = ui.position.left;
                 $("input#tuPBd0hm_top").val(top);
                 $("input#tuPBd0hm_left").val(left);
                 $("#top").html(top);
                 $("#left").html(left);
}
});

Thank you,


try this:

var selected_div = $("input#selected_div").val();
var isDraggable;
if(selected_div == "68") isDraggable = true;
else isDraggable = false

$("#a68").draggable({ 
          containment: 'parent',
          disabled: isDraggable,
          handle: 'drag_border',
          drag: function(e, ui) {
                 var top = ui.position.top;
                 var left = ui.position.left;
                 $("input#tuPBd0hm_top").val(top);
                 $("input#tuPBd0hm_left").val(left);
                 $("#top").html(top);
                 $("#left").html(left);
          }
});

And if you want to be able to disable or enable the div from being draggable after the page has been loaded then look at jquery Draggable API and click the Methods tab

$("#a68").draggable("disable");
$("#a68").draggable("enable");

I hope this helps!


An ID in html must begin with a letter, so "#68" really shouldn't select anything. Try putting a letterr a-z in the front of the ID.

0

精彩评论

暂无评论...
验证码 换一张
取 消