Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

jQuery UI Draggable refreshPositions Option

  • Last Updated : 26 Jan, 2022

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 Draggable refreshPositions Option. This option is used to calculate all droppable positions on every mousemove. The default value of this option is false.

Syntax:

The refreshPositions option takes a boolean value and the syntax is as follows.

$( ".selector" ).draggable({ refreshPositions: true });
  • Get the refreshPositions option

    var refreshPositions = $( ".selector" )
    .draggable( "option", "refreshPositions" );
  • Set the refreshPositions option

    $( ".selector" ).draggable( "option", "refreshPositions", true );

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 Draggable refreshPositions Option.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet"
          href=
    <script src=
    </script>
    <script src=
    </script>
    <style>
        .dragg {
            width: 100px;
            height: 50px;
            border: 1px solid black;
            background-color: blue;
        }
  
        .dropp2{
            width: 250px;
            height: 50px;
            border: 1px solid black;
            float: center;
            background-color: green;
        }
          
        #btn
        {
            padding: 0.5;
            font-size: 20px;
            height: 40px;
            width: 40%;
        }
    </style>
    <script>
        $(function () {
            $("#btn").on('click', function () {
                var refreshPositions = $(".dragg")
                    .draggable( "option", "refreshPositions" );
  
                document.getElementById('gfg').innerHTML +=
                    "RefreshPositions Value : " + refreshPositions;
            });
        });
          
        $(function () {
            $(".dragg").draggable();
            $(".dragg").draggable({
              refreshPositions: true
            });
              
            $(".dropp2").droppable({
                drop: function (event, ui) {
                    $(this)
                        .find("p")
                        .html("Dropped!");
                }
            });
        });
    </script>
</head>
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
        <h3>jQuery UI Draggable refreshPositions 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="Get refreshPositions">
        <h3><span id="gfg"></span></h3>
    </center>
</body>
</html>

Output:

jQuery UI Draggable refreshPositions Option

 jQuery UI Draggable refreshPositions Option

Reference: https://api.jqueryui.com/draggable/#option-refreshPositions


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!