jQuery UI Droppable Accept

Drag and drop car to 'Cars only', motocycle to 'Motocycles only'.
ExampleJquery ui droppable accept
Source Code Expand
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="http://www.pureexample.com/js/lib/jquery.ui.touch-punch.min.js"></script>


<!-- CSS -->
<style type="text/css">
.square {
    width: 100px;
    height: 100px;
    border: 1px solid black;
    margin-bottom: 5px;
    margin-left: 5px;
    text-align: center;
    line-height: 100px;
    float: left;
    background-color: lightblue;
    cursor: pointer;
}

.squaredotted {
    width: 150px;
    height: 150px;
    border: 1px dotted gray;
    margin-bottom: 5px;
    margin-left: 5px;
    text-align: center;
    line-height: 150px;
    float: left;
    background-color: lightgray;
}
</style>


<!-- Javascript -->
<script>
$(function () {
	$(".square").draggable();
	$("#CarsParkinglot").droppable({
		accept: "#car",
		drop: function (event, ui) {
			$(this).css("background-color", "lightgreen")
		},
		out: function (event, ui) {
			$(this).css("background-color", "")
		}
	});
	$("#MotocyclesParkinglot").droppable({
		accept: "#motocycle",
		drop: function (event, ui) {
			$(this).css("background-color", "lightgreen")
		},
		out: function (event, ui) {
			$(this).css("background-color", "")
		}
	});
});
</script>

<!-- HTML -->
<div style="float:left">
    <div id="car" class="square">Car</div>          	
</div>
<div style="float:left">
    <div id="motocycle" class="square">Motocycle</div>          	
</div>
<div style="float:left;margin-left:50px;">
    <div id="CarsParkinglot" class="squaredotted">Cars only</div> 
  	<div id="infoCars"></div>
</div>
<div style="float:left;margin-left:50px;">
    <div id="MotocyclesParkinglot" class="squaredotted">Motocycles only</div> 
  	<div id="infoMotocycles"></div>
</div>


comments powered by Disqus