jQuery UI draggable Options grid

Set how many steps(pixels) in x or y will move.
$("#eleID").draggable({grid: [ 100, 100 ] });

This demostrates that how option grid works, you can alter x or y pixels yourself and drag around cube
to see how option grid affects it`s moving behaviour.
ExampleJquery ui draggable options grid
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: 200px;
    height: 200px;
    border: 1px solid black;
    margin-bottom: 5px;
    margin-left: 5px;
    text-align: center;
    line-height: 200px;
    float: left;
    background-color: lightblue;
    cursor: pointer;
}
</style>


<!-- Javascript -->
<script>
    $(function () {
        $("#dragitem").draggable({
            grid: [ 100, 100 ]
        });
        
        $("#x,#y").keyup(function(){           
            var xpiexls = $("#x").val();
            var ypiexls = $("#y").val();
            
            $("#dragitem").draggable("option", "grid", [ xpiexls, ypiexls ]);
            $("#info").html("x,y piexls is <font color=\"red\">" + xpiexls + "," + ypiexls + "</font>");
        });
    });
</script>

<!-- HTML -->
<div style="float:left">
    <div id="dragitem" class="square">
		<span id="info">x,y piexls is <font color="red">100,100</font></span>
	</div>          	
</div>
<div style="clear:both">
	set x piexls : <input id="x" type="text" value="100"> (pixels)
    <br/>
    set y piexls : <input id="y" type="text" value="100"> (pixels)
</div>


comments powered by Disqus