jQuery UI的Draggable instance()方法

jQuery UI的Draggable instance()方法

jQuery UI是一种基于网络的技术,由各种GUI部件、视觉效果和主题组成。这些功能可以使用jQuery的JavaScript库来实现。

jQuery UI是为网页建立UI界面的最佳工具。它也可以用来构建高度互动的网络应用程序,或者可以用来轻松地添加小工具。

在这篇文章中,我们将使用jQuery UI Draggable instance() 方法来检索dragable的实例对象。如果该元素没有任何相关的实例,”undefined “将被返回。它不接受任何参数来运作。

语法:

var Instance = $( ".selector" ).draggable( "instance" );

参数:该方法不接受任何参数。

返回类型:该方法返回一个对象值,其中包含可拖动的实例对象。

CDN链接:添加以下你的项目需要的jQuery Mobile脚本。

<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css”>
<script src= “https://code.jquery.com/jquery-1.12.4.js”></script>
<script src= “https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>

例子:这个例子演示了jQuery UI Draggable instance()方法。

<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href=
"//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.12.4.js">
    </script>
    <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js">
    </script>
  
    <style>
        .drag {
            width: 90px;
            height: 40px;
            border: 1px solid black;
            background-color: blue;
        }
  
        .drop2,
        .drop3 {
            width: 200px;
            height: 40px;
            border: 1px solid black;
            float: center;
            background-color: green;
        }
  
        #btn {
            padding: 0.5;
            font-size: 25px;
            height: 40px;
            width: 150px;
        }
    </style>
  
    <script>
        (function () {
            ("#btn").on('click', function () {
                var insta = (".drop2").draggable("instance");
                console.log(insta);
            });
  
            (".drag").draggable();
            $(".drop2").droppable();
        });
    </script>
</head>
  
<body>
    <center>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
  
        <h3>jQuery UI Draggable instance() 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="Instance">
        <h4><span id="spanID"></span></h4>
    </center>
</body>
  
</html>

输出:

jQuery UI的Draggable instance()方法

jQuery UI的Draggable instance()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程