Moving (drag) three Ivs at the same time and disabling with a checkbox

Asked

Viewed 34 times

1

I’m using this code to move Ivs simultaneously: https://github.com/someshwara/MultiDraggable

The logic: If checkbox is checked, use drag in group, otherwise use drag per unit'.

But once unchecked the checkbox (to use drag per unit) the same is not working as it should in the following example: https://jsfiddle.net/L56yvyms/1/

            $('document').ready(function() {


              $("#checkboxDragAll").click(function() {

                if ($(this).is(':checked')) 
                {

                    //Se 'checkbox marcado' drag funciona em "grupo"
                        $(".d").multiDraggable({
                          group: $(".d")
                        });

                    //Setando o drag em .d2 em "unidade"
                        // $(".d").multiDraggable({
                        //  group: ""
                        //});


                } else {
                          //Se 'checkbox desmarcado' drag deveria funcionar em "unidade"!!!
                          // Mas se anteriormente setado em "grupo", 
                          // o drag em "unidade" não está funcionando.

                          $(".d").draggable( "destroy" );
                          $(".d").draggable();


                };

              });
            });

Somebody save me? : B

  • E.. I understand you :) But I took a look, there are problems even in draggable "Destroy". From what I saw when unchecking, he does one at a time, that is, when scoring and unchecking 3 times it works :P...

  • Um, let me take a look at that, if that’s how it is, just do one each on the Divs I think =)

  • That’s what I thought. But it didn’t work, I ran some tests with each

  • It is I tested and it did not work tmb Samir

1 answer

1


After a good research I found a kind of improvement of this function multiDraaggable(). You can see it here: https://github.com/wizztjh/MultiDraggable/blob/master/multidraggable.js

He basically adds that to the code:

if (opts == "destroy") {
  return this.each(function() {
    $(this)
      .draggable("destroy")
      .unbind(".multiDraggable")
      .data("init", "");
  });
}

In addition to making some small but interesting modifications, I think. So I advise you to follow this update.

With these amendments, we now have the argument "destroy", also to the .draggable('destroy') "native". So just do this in your code:

$('document').ready(function() {
  $("#checkboxDragAll").click(function() {
    if ($(this).is(':checked')) {
      $(".d").multiDraggable({
        group: $('.d')
      });
    } else {
      $(".d").multiDraggable('destroy');
      $(".d").draggable()
    };
  });
});

You can see running here below:

Demonstration - Jsfiddle

  • 1

    Poxa Samir, you are too much, thank you very much from my heart! = ) I’m already opening the page =D

  • @user31050 Thanks rsrs guy, happy to have helped.. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.