jQuery UI selectable tolerance选项
jQuery UI由GUI小工具、视觉效果和使用jQuery JavaScript库实现的主题组成。jQuery UI对于构建网页的UI界面非常有用。它可以用来建立高度互动的网络应用程序,也可以用来轻松地添加小工具。
jQuery UI可选择的公差选项是用来决定使用哪种模式来测试套索是否应该选择一个项目。套索可以指的是要通过拖动盒子来选择的元素。它是字符串类型的,其默认值是 “触摸”。
以下是可能的值。
- fit : 指定套索何时与项目完全重合。
- touch : 它指定了套索与项目重叠的具体数量。
语法:
用公差选项初始化可选择的元素。
$( "Selector" ).selectable({ tolerance: "fit" });
- 获取tolerance选项。
var tolerance = $( "Selector" ).selectable( "option", "tolerance" );
- 设置tolerance选项。
$( "Selector" ).selectable( "option", "tolerance", "fit" );
CDN链接:下面是一些jQuery Mobile脚本,你的项目将需要这些脚本,所以要把它们添加到你的项目中。
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/smoothness/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 Mobile Selectable tolerance选项**的用途。
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href=
"https://code.jquery.com/ui/1.12.1/themes/smoothness/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>
<style>
h1 {
color: green;
}
#list .ui-selecting {
background: greenyellow;
}
#list .ui-selected {
color: white;
background: green;
}
</style>
<script>
(document).ready(function() {
("#Button").on('click', function() {
var tolerance = ("#list").selectable(
"option", "tolerance");
("#gfg").html(tolerance);
});
});
</script>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h3>jQuery UI Selectable tolerance Option</h3>
<ul id="list" style="list-style: none">
<li>Data Structure</li>
<li>Algorithm</li>
<li>C++</li>
<li>Java</li>
<li>HTML</li>
<li>Bootstrap</li>
<li>PHP</li>
</ul>
<input type="button"
id="Button"
value="Value of the tolerance option">
<h4>
<span id="gfg"></span>
</h4>
</center>
<script>
(document).ready(function() {
("#list").selectable();
});
</script>
</body>
</html>
输出: