Results 1 to 2 of 2

Thread: HTML div class="drag"

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2020
    Posts
    59

    HTML div class="drag"

    Hello Everyone,

    How to disable drag and drop after 6 drags in HTML using draggable.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: HTML div class="drag"

    By draggable, I am assuming you're referring to jQuery UI's draggable API.

    You will need to do the following:
    1. Handle the start event
    2. Increment the number of times the lement has been dragged by storing the value in variable (or data tag on element)
    3. Handle the stop event
    4. Check if the number of times equals 6
    5. If so, then destroy the draggable binding


    Example:
    Code:
    $(function() {
      var count = 0;
      $( ".drag" ).draggable({
        start: function() {
          count++;
        },
        stop: function(event, ui) {
          if (count === 6) {
            $(ui.helper[0]).draggable("destroy");
          }
        }
      });
    });
    Live Demo: Fiddle
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width