jQuery UI Sortable Containment

Containment is used for creating a boundary that can constrain draggable items.
ExampleJquery ui sortable containment
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">
.list {
    background-color: pink;
    font-size: 30px;
    text-align: center;
    cursor: pointer;
    font-family: Geneva,
        Arial,
        Helvetica,
        sans-serif;
    border: 1px solid gray;
}

.items.ui-selected {
    background: red;
    color: white;
    font-weight: bold;
}

.items {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

.items li {
    float: left;
    margin: 2px;
    padding: 2px;
    width: 50px;
    height: 50px;
    line - height: 50px;
}

.highlight {
    border: 2px solid red;
    font-weight: bold;
    font-size: 50px;
    background-color: lightblue;
}
</style>


<!-- Javascript -->
<script>
$(function () {
	$("#items1").sortable({
		containment: "#container1"
	});
	$("#items2").sortable({
		containment: "#container2"
	});
	$("#items1,#items2").disableSelection();
});
</script>

<!-- HTML -->
<div id="container1" style="float:left;width:280px;border:1px solid black;height:200px">
    <ul id="items1" class="items">
        <li class="list">1</li>
        <li class="list">2</li>
        <li class="list">3</li>
        <li class="list">4</li>
        <li class="list">5</li>
        <li class="list">6</li>
        <li class="list">7</li>
        <li class="list">8</li>
        <li class="list">9</li>
        <li class="list">10</li>
        <li class="list">11</li>
        <li class="list">12</li>
    </ul>
</div>
<div id="container2" style="float:left;width:280px;border:1px solid black;height:200px;margin-left:100px;">
    <ul id="items2" class="items">
        <li class="list">1</li>
        <li class="list">2</li>
        <li class="list">3</li>
        <li class="list">4</li>
        <li class="list">5</li>
        <li class="list">6</li>
        <li class="list">7</li>
        <li class="list">8</li>
        <li class="list">9</li>
        <li class="list">10</li>
        <li class="list">11</li>
        <li class="list">12</li>
    </ul>
</div>


comments powered by Disqus