jQuery 交互式可放置元素
描述
Drop-able函数可以与JqueryUI中的交互一起使用。此函数可以在任何DOM元素上启用可放置的功能。我们可以通过鼠标点击将可拖动的元素放置。
语法
以下是使用draggable的简单语法-
$( "#droppable" ).droppable();
示例
以下是一个简单示例,演示了可拖动的用法 –
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "https://www.tutorialspoint.com/jquery/jquery-3.6.0.js">
</script>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
</script>
<script type = "text/javascript" language = "javascript">
(function() {( "#draggable" ).draggable();
( "#droppable" ).droppable({
drop: function( event, ui ) {( this ).addClass( "ui-state-highlight" ).find( "p" ).html( "Dropped!" );
}
});
});
</script>
<style>
#draggable { width: 100px; height: 100px;
padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
#droppable { width: 150px; height: 150px;
padding: 0.5em; float: left; margin: 10px; }
</style>
</head>
<body>
<div id = "draggable" class = "ui-widget-content">
<p>Drag</p>
</div>
<div id = "droppable" class = "ui-widget-header">
<p style = "background-color: aquamarine;height: 50;">Drop here</p>
</div>
</body>
</html>
这将产生以下结果−