jQuery UI Sortable distance选项

jQuery UI Sortable distance选项

jQuery UI是一种基于网络的技术,由各种GUI部件、视觉效果和主题组成。这些功能可以通过jQuery,JavaScript库来实现。jQuery UI是为网页建立UI界面的最佳工具。它也可以用来构建高度互动的网络应用程序,或者可以用来轻松添加小工具。

在这篇文章中,我们将学习jQuery UI Sortable distance选项,该选项规定在鼠标拖动超过指定距离后才会开始排序。它可以用于允许点击适用距离内的元素。它是数字类型,其默认值为1。

语法:

$( "Selector" ).sortable({ distance: 10 });
  • 设置distance选项。
$( "Selector" ).sortable( "option", "distance", 10 );
  • 获得distance选项。
var distance = $( "Selector" ).sortable( "option", "distance" );

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可排序的distance选项,我们将设置距离选项为10,开始事件将触发,将显示当前距离选项。

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <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>
    <title>jQuery UI Sortable distance option</title>
    <style>
        #sortableList {
            list-style-type: none;
        }
        .geeks {
            margin: 10px;
            background: lightgreen;
            padding: 10px;
            border: 1px solid green;
            font-size: 25px;
        }
    </style>
    <script>
        (function() {
            ('#sortableList').sortable({
                start: function(event, ui) {
                    ("#sortedList").html(("#sortedList").html() 
                    + "Start event triggered when distance is " 
                    + $("#sortableList").sortable("option", "distance") 
                    + "<br>");
                },
                distance: 10
            });
        });
    </script>
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
        <h2>jQuery UI Sortable distance option</h2>
        <ul id="sortableList">
            <li id="Tutorials" class="geeks">
                1.Free Tutorials 
            </li>
            <li id="Articles" class="geeks">
                2.Millions of articles 
            </li>
            <li id="Webinars" class="geeks">
                3.Webinars by Industry Experts 
            </li>
            <li id="Courses" class="geeks">
                4.Live, Online and Classroom Courses 
            </li>
        </ul>
        <h2>
            <span id='sortedList'></span>
        </h2>
    </center>
</body>
  
</html>

输出:

jQuery UI Sortable distance选项

jQuery UI可排序的距离选项

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程