jQuery UI的Droppable deactivate事件
jQuery UI是一种基于网络的技术,由GUI部件、视觉效果和使用jQuery、JavaScript库实现的主题组成。它也可以用来建立高度互动的网络应用程序,或者可以用来轻松添加小工具。
jQuery UI Droppable deactivate事件是用来在一个被接受的可拖动物体停止拖动时触发。
语法:
我们需要用停用回调函数来初始化Droppable小组件。
$( ".selector" ).droppable({
deactivate: function( event, ui ) {}
});
- 将一个事件监听器绑定到dropdeactivate事件上。
$( ".selector" ).on( "dropdeactivate ", function( event, ui ) {} );
参数:这些是可以接受的下列参数。
- event。当分类创建一个项目时,该事件被触发。
- ui。该参数为对象类型,有以下选项。
- helper。这个参数是代表排序帮助器的jQuery对象。
- draggable:这个参数是代表可拖动元素的jQuery对象。
- offset。这个参数是帮助者对象的当前绝对位置,它被表示为 { top, left }。
- position。这个参数是帮助者对象的当前位置,它被表示为 { top, left }。
CDN链接:你的项目将需要以下jQuery Mobile脚本,所以我们需要将这些脚本添加到你的项目中。
<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel = “stylesheet”>
<script src = “https://code.jquery.com/jquery-1.10.2.js”></script>
<script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
例子:这个例子描述了jQuery UI Droppable deactivate事件的用途。
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href=
"https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css">
<script src=
"https://code.jquery.com/jquery-1.10.2.js">
</script>
<script src=
"https://code.jquery.com/ui/1.10.4/jquery-ui.js">
</script>
<style>
.dragg {
width: 120px;
height: 60px;
border: 1px solid black;
background-color: blue;
}
.dropp2{
width: 250px;
height: 50px;
border: 1px solid black;
float: center;
background-color: green;
}
#btn
{
padding: 0.5;
font-size: 20px;
height: 40px;
width: 40%;
}
</style>
<script>
(function () {
("#btn").on('click', function () {
(".dropp2").droppable({
deactivate : function (event, ui) {
("#gfg").html (("#gfg").html ()
+ "<b>Droppable Widget has "
+ "been deactivated.</b><br>");
}
});
});
});
(function () {
(".dragg").draggable();
(".dropp2").droppable({
drop: function (event, ui) {
$(this)
.find("p")
.html("Dropped!");
}
});
});
</script>
</head>
<body>
<center>
<h1 style="color:green;">GeeksforGeeks</h1>
<h3>jQuery UI Droppable deactivate Event</h3>
<div class="dragg">
<p>Drag</p>
</div>
<br>
<div class="dropp2">
<p>Drop here</p>
</div>
<br>
<input type="button" id="btn"
value="Click">
<h3><span id="gfg"></span></h3>
</center>
</body>
</html>
输出:
jQuery UI的Droppable deactivate事件