jQuery UI draggable Options snapTolerance

The distance between each of two draggable elements edge where snapping occurs.
$("#eleID").draggable({ snapTolerance: 20  });

Try to drag squares close to each other and adjust snap tolerance to see the difference.

Related option
snapsnap mode
ExampleJquery ui draggable options snaptolerance
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">
.drag {
    width: 100px;
    height: 100px;
    line-height: 100px;
    border: 1px solid black;
    cursor: pointer;
    border-radius: 10px;
    text-align: center;
    background-color: lightpink;
    position: relative;

.container {
    background-color: lightblue;
    width: 500px;
    height: 400px;
    border: 1px solid black;
    float: left;
    margin-right: 30px;

<!-- Javascript -->
    $(function () {
            snap: true,
            snapTolerance: 20
            range: "min",
            value: 20,
            min: 10,
            max: 50,
            step: 1,
            slide: function (event, ui) {
                $("#drag1").draggable("option", "snapTolerance", ui.value);
				$("#drag2").draggable("option", "snapTolerance", ui.value);

<!-- HTML -->
Slide to adjust dragging snap tolerance : <span id="info" style="color:red">20</span>
<div id="slider" style="width:300px"></div>
<div id="c1" class="container">    
    <div id="drag1" class="drag" style="left:20px;top:20px;">drag me</div>
    <div id="drag2" class="drag" style="left:20px;top:50px;background-color:lightgray">drag me</div>
<div style="clear:both"/>

comments powered by Disqus