jQuery UI Widget arrastrable() Método

jQuery UI  es una tecnología basada en la web y consta de widgets GUI, efectos visuales y temas implementados mediante jQuery, JavaScript Library. jQuery UI es la mejor herramienta para crear interfaces de interfaz de usuario para las páginas web. También se puede usar para crear aplicaciones web altamente interactivas o se puede usar para agregar widgets fácilmente.

En este artículo, usaremos el método jQuery UI Draggable widget() para devolver un objeto jQuery que contiene el elemento Draggable. No acepta ningún parámetro para su funcionamiento.

Sintaxis:

var widget = $( ".selector" ).draggable( "widget" );

Parámetro: Este método no acepta ningún parámetro.

Tipo de devolución: este método devuelve un valor de objeto que contiene el elemento que se puede arrastrar.

Enlace CDN: agregue estos scripts jQuery Mobile que serán necesarios para su proyecto.

<enlace href = «https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css» rel = «hoja de estilo»>
<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>

Ejemplo: Este ejemplo demuestra el método jQuery UI Draggable widget() .

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <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>
      
    <style>
        .drag
        {
            width: 90px; height: 50px;
            border: 1px solid black;
            background-color:blue;
        }
        .drop2
        {
            width: 200px; height: 50px;
            border: 1px solid black;
            float : center;
            background-color:green;
        }
    </style>
      
    <script>
        $(function() {
            $("#btn").on('click', function () {
                var widget = $(".drag").draggable( "widget" );
                document.getElementById('spanID').innerHTML += 
                    "No of jQuery object : " 
                     + Object.keys(widget).length;
            });
              
            $( ".drag" ).draggable();
            $( ".drop2" ).droppable({
            drop: function( event, ui ) {
                $( this ).find( "p" ).html( "Dropped!" );
            }
            });
        });
    </script>
</head>
  
<body>
    <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
        <h3>jQuery UI Draggable widget() method</h3>
        <div class="drag">
            <p>Drag</p>
        </div>
        <br>
        <div class="drop2">
            <p>Drop here</p>
        </div>
        <br>
        <input type="button" id="btn" value="Widget">
        <h4><span id="spanID"></span></h4>
    </center>
</body>
</html>

Producción:

jQuery UI Draggable widget() Method

jQuery UI Widget arrastrable() Método

Referencia: https://api.jqueryui.com/draggable/#method-widget

Publicación traducida automáticamente

Artículo escrito por SHUBHAMSINGH10 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *