English | 正體中文 | 简体中文

Jquery ui draggable snap to



范例程式码 Expand
<!-- Javascript -->
<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>
    $(function () {
        $(".square").draggable({
            snap: ".squaredotted",
            snapMode: "inner"
        });
    });
</script>

<!-- HTML -->
<style>
    .square {
  		width:50px;
        height:50px;
        border:1px solid black;         
        margin-bottom:5px;
        margin-left:5px;
        text-align:center;
        line-height:50px;
        float:left;
        background-color:lightblue;
    }
  
  	.squaredotted{
  		width:50px;
        height:50px;
        border:1px dotted gray;         
        margin-bottom:5px;
        margin-left:5px;
        text-align:center;
        line-height:50px;
        float:left;
    }
</style>
<div>Move squares to the right, squares will snap into position</div>
<div style="float:left">
    <div class="square">1</div>
    <div class="square">2</div>
    <div class="square">3</div>
    <div style="clear:both"></div>
    <div class="square">4</div>
    <div class="square">5</div>
    <div class="square">6</div>
    <div style="clear:both"></div>
    <div class="square">7</div>
    <div class="square">8</div>
    <div class="square">9</div>
</div>
<div style="float:left;margin-left:50px;">
    <div class="squaredotted">1</div>
    <div class="squaredotted">2</div>
    <div class="squaredotted">3</div>
    <div style="clear:both"></div>
    <div class="squaredotted">4</div>
    <div class="squaredotted">5</div>
    <div class="squaredotted">6</div>
    <div style="clear:both"></div>
    <div class="squaredotted">7</div>
    <div class="squaredotted">8</div>
    <div class="squaredotted">9</div>
</div>

    
在线测试程序
© 2012 PureExample.com contact