jQuery UI Sortable tolerance选项

jQuery UI Sortable tolerance选项

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

在这篇文章中,我们将学习jQuery UI Sortable tolerance选项,它指定了哪种模式可以用来测试被移动的项目是否在另一个项目上盘旋。它是字符串类型的,其默认值是 “intersect”。

tolerance选项的可能值:

  • intersect: 当项目与其他项目至少重叠50%时,将开始排序。
  • pointer。当鼠标指针与其他项目重叠时,将开始进行排序。

语法:

用具有特定字符串值的tolerance选项初始化可排序。

$( "Selector" ).sortable({ tolerance: "pointer" });
  • 设置tolerance选项。
$( "Selector" ).sortable( "option", "tolerance", "pointer" );
  • 得到tolerance选项。
var tolerance = $( "Selector" ).sortable( "option", "tolerance" );

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 Sortable tolerance 选项,我们将设置tolerance option的值为 “pointer”,开始事件将触发,显示当前tolerance 选项。

<!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 tolerance 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 tolerance is " 
                    + $("#sortableList").sortable("option", "tolerance") 
                    + "<br>");
                },
                tolerance: "pointer"
            });
        });
    </script>
</head>
  
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
        
        <h2>jQuery UI Sortable tolerance 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 tolerance选项

jQuery UI Sortable tolerance选项

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程