jQuery UI 是一种基于 Web 的技术,由各种 GUI 小部件、视觉效果和主题组成。这些函数可以使用 jQuery、JavaScript 库来实现。 jQuery UI 是构建网页 UI 接口的最佳工具。它还可用于构建高度交互的 Web 应用程序,或者可用于轻松添加小部件。
在本文中,我们将学习 jQuery UI 可排序距离选项,该选项指定在鼠标拖动超出指定距离后才会开始排序。它可以用于允许在适用距离内点击元素。它是数字类型,默认值为1。
用法:
$( "Selector" ).sortable({ distance: 10 });
- 
设置距离选项:
$( "Selector" ).sortable( "option", "distance", 10 );
 - 
获取距离选项:
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 可排序距离选项,我们将距离选项设置为 10,并且将触发开始事件,显示当前的距离选项。
HTML
<!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 可排序距离选项
参考: https://api.jqueryui.com/sortable/#option-distance
相关用法
- jQuery UI Sortable disabled用法及代码示例
 - jQuery UI Sortable disable()用法及代码示例
 - jQuery UI Sortable delay用法及代码示例
 - jQuery UI Sortable destroy()用法及代码示例
 - jQuery UI Sortable dropOnEmpty用法及代码示例
 - jQuery UI Sortable deactivate用法及代码示例
 - jQuery UI Sortable revert用法及代码示例
 - jQuery UI Sortable opacity用法及代码示例
 - jQuery UI Sortable cursorAt用法及代码示例
 - jQuery UI Sortable cancel用法及代码示例
 - jQuery UI Sortable appendTo用法及代码示例
 - jQuery UI Sortable axis用法及代码示例
 - jQuery UI Sortable classes用法及代码示例
 - jQuery UI Sortable Cursor用法及代码示例
 - jQuery UI Sortable out用法及代码示例
 - jQuery UI Sortable sort用法及代码示例
 - jQuery UI Sortable start用法及代码示例
 - jQuery UI Sortable stop用法及代码示例
 - jQuery UI Sortable update用法及代码示例
 - jQuery UI Sortable enable()用法及代码示例
 - jQuery UI Sortable refresh()用法及代码示例
 - jQuery UI Sortable cancel()用法及代码示例
 - jQuery UI Sortable refreshPositions()用法及代码示例
 - jQuery UI Sortable receive用法及代码示例
 - jQuery UI Sortable forceplaceholderSize用法及代码示例
 
注:本文由纯净天空筛选整理自harshsethi2000大神的英文原创作品 jQuery UI Sortable distance Option。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
