我对我的可拖放模块是否有疑问,我这里有课程
如果 Customer George (客户乔治)在在路上课程中,在厨房中课程将不允许/接受放弃客户乔治再次来到那个盒子。它将显示警报,表明客户已经在步骤2中。
场景需要验证: 如果客户George 已经在类stackDrop2中,则类stackDrop1停止接受客户George 。
我的Jquery代码:
$(".drag-wrapper").draggable({
appendTo: "body",
cursor: "move",
helper: 'clone',
});
$("#launchPad").droppable({
tolerance: "intersect",
accept: ".drag-wrapper",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
// $("#launchPad").append($(ui.draggable));
}
});
$(".stackDrop1").droppable({
tolerance: "intersect",
accept: ".drag-wrapper",
revert: 'invalid',
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
alert('In the kitchen');
}
});
$(".stackDrop2").droppable({
tolerance: "intersect",
accept: ".drag-wrapper",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
alert('On the road');
}
});
$(".stackDrop3").droppable({
tolerance: "intersect",
accept: ".drag-wrapper",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
alert('Completed');
}
});
我的HTML代码:
<div class="jumbotron" style="background-color:white;">
<div class="row">
<div class="col-md-3">
<div id="launchPad">
<div class="stackHdr" style="background: linear-gradient(-25deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>Open Orders</text>
</div>
@foreach($customer_orders_details as $transac_details)
<div class="drag-wrapper">
<div class="card">
<div class="card-body" style="font-weight: bold; text-align: center;">
<h5 class="card-title" style="text-align: center;">
<i class="far fa-user-circle" style="font-size:30px;"></i>
<br><br>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: 300; color:black !important; font-family: 'Open Sans';">OR # {{$transac_details->or_number}}</h6>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: bold; color:black !important;">Customer: {{$transac_details->customer_name}}</h6><br>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: 300;">Address: {{$transac_details->order_ship_address}}</h6>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: 300;">Contact #: {{$transac_details->customer_number}}</h6>
<p class="card-text">Total:${{$transac_details->amount}}</p>
<a href="#" class="card-link btn btn-primary">Assign</a>
<a href="#" class="card-link btn btn-warning" id="gather_customer_order" data-order-id='{{$transac_details->order_id}}' data-customer-id='{{$transac_details->customer_id}}' style="color:white;" data-toggle="modal" data-target="#customer_detail_delivery">Details</a>
</h5>
</div>
</div>
</div>
<br>
@endforeach
</div>
</div>
<div class="col-md-3">
<div id="dropZone">
<div class="stack" style="width:231px;">
<div class="stackHdr" style="background: linear-gradient(-10deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>In the Kitchen</text>
</div>
<center>
<div class="stackDrop1" style="">
</div>
</center>
</div>
</div>
</div>
<div class="col-md-3">
<div id="dropZone">
<div class="stack" style="width:231px;">
<div class="stackHdr" style="background: linear-gradient(-10deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>On the Road</text>
</div>
<center>
<div class="stackDrop2" style="">
</div>
</center>
</div>
</div>
</div>
<div class="col-md-3">
<div id="dropZone">
<div class="stack" style="width:231px;">
<div class="stackHdr" style="background: linear-gradient(-10deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>Completed</text>
</div>
<center>
<div class="stackDrop3" style="">
</div>
</center>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
您可以调整可拖动对象的类别,以使每个可放置对象仅适应特定的类别。考虑下面的代码。
$(function() {
$(".drag-wrapper").draggable({
appendTo: "body",
cursor: "move",
helper: 'clone'
});
$("#launchPad").droppable({
tolerance: "intersect",
accept: ".drag-wrapper",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
// $("#launchPad").append($(ui.draggable));
}
});
$(".stackDrop1").droppable({
tolerance: "intersect",
accept: ".from-launch",
revert: 'invalid',
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
ui.draggable.removeClass("from-launch").addClass("from-kitchen");
$(this).append($(ui.draggable));
console.log('In the kitchen');
}
});
$(".stackDrop2").droppable({
tolerance: "intersect",
accept: ".from-kitchen",
activeClass: "ui-state-default",
hoverClass: "ui-state-hover",
drop: function(event, ui) {
$(this).append($(ui.draggable));
console.log('On the road');
}
});
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="jumbotron" style="background-color:white;">
<div class="row">
<div class="col-md-3">
<div id="launchPad">
<div class="stackHdr" style="background: linear-gradient(-25deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>Open Orders</text>
</div>
<div class="drag-wrapper from-launch">
<div class="card">
<div class="card-body" style="font-weight: bold; text-align: center;">
<h5 class="card-title" style="text-align: center;">
<i class="far fa-user-circle" style="font-size:30px;"></i>
<br><br>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: 300; color:black !important; font-family: 'Open Sans';">OR # 1001</h6>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: bold; color:black !important;">Customer: George</h6><br>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: 300;">Address: 123 Main St, City</h6>
<h6 class="card-subtitle mb-2 text-muted" style="font-weight: 300;">Contact #: (415) 555-1212</h6>
<p class="card-text">Total:$0.00</p>
<a href="#" class="card-link btn btn-primary">Assign</a>
<a href="#" class="card-link btn btn-warning" id="gather_customer_order" data-order-id='OR-1001' data-customer-id='C-1' style="color:white;" data-toggle="modal" data-target="#customer_detail_delivery">Details</a>
</h5>
</div>
</div>
</div>
<br>
</div>
</div>
<div class="col-md-3">
<div id="dropZone">
<div class="stack" style="width:231px;">
<div class="stackHdr" style="background: linear-gradient(-10deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>In the Kitchen</text>
</div>
<center>
<div class="stackDrop1" style="height: 400px">
</div>
</center>
</div>
</div>
</div>
<div class="col-md-3">
<div id="dropZone">
<div class="stack" style="width:231px;">
<div class="stackHdr" style="background: linear-gradient(-10deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>On the Road</text>
</div>
<center>
<div class="stackDrop2" style="height: 400px;">
</div>
</center>
</div>
</div>
</div>
<div class="col-md-3">
<div id="dropZone">
<div class="stack" style="width:231px;">
<div class="stackHdr" style="background: linear-gradient(-10deg, #00e4d0, #5983e8); color:white; text-align: center;">
<text>Completed</text>
</div>
<center>
<div class="stackDrop3" style="height: 400px;">
</div>
</center>
</div>
</div>
</div>
</div>
</div>
当用户将项目从一个地方移到另一个地方时,将向该项目添加和删除类。每个可放置对象随后都可以接受特定的类项目。这样可以防止用户将项目移到错误的位置。
希望有帮助。