Open In App

jQuery UI Droppable tolerance Option

Improve
Improve
Like Article
Like
Save
Share
Report

jQuery UI  is a web-based technology and consists of GUI widgets, visual effects, and themes implemented using the jQuery, JavaScript Library. jQuery UI is the best tool for building UI interfaces for the webpages. It can also be used to build highly interactive web applications or can be used to add widgets easily.

In this article, we will learn how to use the jQuery UI Droppable tolerance Option. This option is used to determine which mode to use for testing whether a draggable is hovering over a droppable. The default value of this option is “intersect”.

The following are the possible values:

  • “fit”: It specifies the draggable overlaps the droppable entirely.
  • intersect”: It specifies the draggable overlaps the droppable at least 50% in both directions.
  • “pointer”: It specifies the mouse pointer overlaps the droppable.
  • “touch”: It specifies the draggable overlaps the droppable any amount.

Syntax:

The tolerance option takes an above-defined type value and the syntax is as follows.

$( ".selector" ).draggable({
tolerance: "fit"
});
  • Get the tolerance option

    var tolerance = $( ".selector" ).droppable( "option", "tolerance" );
  • Set the tolerance option

    $( ".selector" ).droppable( "option", "tolerance", "fit" );

CDN Link: The following jQuery Mobile scripts will be needed for your project so we need to add these scripts to your project.

<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel = “stylesheet”>
<script src = “https://code.jquery.com/jquery-1.10.2.js”></script>
<script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>

Example: This example describes the uses of the jQuery UI Droppable tolerance Option.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <link rel="stylesheet"
          href=
    <script src=
    </script>
    <script src=
    </script>
  
    <style>
        .dragg {
            width: 90px;
            height: 60px;
            border: 1px solid black;
            background-color: blue;
            font-size: 20px;
        }
  
        .dropp2{
            width: 250px;
            height: 60px;
            font-size: 20px;
            border: 1px solid black;
            float: center;
            background-color: green;
        }
          
        #btn
        {
            padding: 0.5;
            font-size: 20px;
        }
    </style>
  
    <script>
        $(function () {
            $("#btn").on('click', function () {
                var tolerance = $(".dropp2")
                   .droppable( "option", "tolerance" );
                $("#gfg").html(tolerance);
            });
        });
          
        $(function () {
            $(".dragg").draggable();
            $(".dropp2").droppable({
                drop: function (event, ui) {
                    $(this)
                        .find("p")
                        .html("Dropped!");
                }
            });
        });
    </script>
</head>
  
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
  
        <h3>jQuery UI Droppable tolerance Option</h3>
  
        <div class="dragg">
            <p>Drag</p>
        </div>
        <br>
        <div class="dropp2">
            <p>Drop here</p>
        </div>
        <br>
        <input type="button" id="btn"
            value="Value of the tolerance option">
          
        <h3><span id="gfg"></span></h3>
    </center>
</body>
  
</html>


Output:

jQuery UI Droppable tolerance Option

 jQuery UI Droppable tolerance Option

Reference: https://api.jqueryui.com/droppable/#option-tolerance



Last Updated : 29 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads