在使用拖放字段或元素到容器时,是否有办法在页面上生成多个放置区域?例如,如果我有一个容器,当一个字段放在它上面时,它将动态生成顶部,左侧,右侧和底部放置区域。所以我可以选择格式化行和列的字段。像这样Demo page。我想将这些字段样式/设置存储到数据库中。
任何人都会遇到这样的事情?
答案 0 :(得分:-1)
当然,只需使用一个类作为dropzone选择器 (基于https://jqueryui.com/droppable/的代码)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Droppable - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<style>
#draggable { width: 70px; height: 70px; padding: 0.5em; margin: 10px 10px 10px 0; border: 1px solid #000000}
.droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; border: 1px solid #555555 }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$(function() {
$("#draggable").draggable();
$(".droppable").droppable({
drop: function( event, ui ) {
// detect which dropzone the object was dropped into
var index = $(".droppable").index(this);
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped in box with index: " + index);
}
});
});
</script>
</head>
<body>
<div id="draggable" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div class="droppable" class="ui-widget-header">
<p>Drop here</p>
</div>
<div class="droppable" class="ui-widget-header">
<p>no, Drop here</p>
</div>
<div class="droppable" class="ui-widget-header">
<p>rather, Drop here</p>
</div>
<div class="droppable" class="ui-widget-header">
<p>you should really Drop here</p>
</div>
</body>
</html>