0

真的只是在寻找想法。我想要的是当两个带有图像的 div 彼此靠近时,移动它们的位置以相互连接。任何想法如何做到这一点?

HTML

<body onkeyup="clearPress()" onkeydown="controlCheck(event)" style="cursor: auto;">
    <div id="application" style="position:absolute">
        <div id="accordion" class="ui-accordion ui-widget ui-helper-reset" style="position:absolute;top:0px;left:0px;width:300px;height:900px" role="tablist"> … </div>
        <div id="buttons" style="position:absolute;top:0px;left:315px;width:1100px;height:50px;border:2px solid grey;background: url('images/ui-bg_glass_75_e6e6e6_1x400.png') repeat-x scroll 50% 50% rgb(230, 230, 230);"> … </div>
        <div id="canvas" class="DROPPABLE ui-droppable" style="position:absolute;top:50px;left:315px;width:1100px;height:850px;border:2px solid grey">
        <div class="DRAGGABLE ui-draggable" style="position: absolute; width: 120px; height: 60px; top: 123.817px; left: 507.7px;" onclick="addBorder(this)">
            <img id="PMF00" src="/devices/AAU01-010.gif"></img>
        </div>
        <div class="DRAGGABLE ui-draggable" style="position: absolute; width: 42px; height: 42px; top: 988.7px; left: -344.3px;" onclick="addBorder(this)"> … </div>
        <div class="DRAGGABLE ui-draggable" style="position: absolute; width: 84px; height: 36px; top: 138.7px; left: 412.467px;" onclick="addBorder(this)"> … </div>
        <div class="DRAGGABLE ui-draggable" style="position: absolute; width: 80px; height: 41px; top: 143.7px; left: 151.7px;" onclick="addBorder(this)"> … </div>
        <div class="DRAGGABLE ui-draggable" style="position: absolute; width: 100px; height: 100px; top: 92px; left: 344px;" onclick="addBorder(this)"> … </div>
    </div>
</div>

看图解释

4

2 回答 2

0

使用指定的 snap 选项初始化可拖动对象:

$( ".selector" ).draggable({ snap: true });

初始化后获取或设置 snap 选项:

// getter
var snap = $( ".selector" ).draggable( "option", "snap" );
// setter
$( ".selector" ).draggable( "option", "snap", true );
于 2013-10-28T11:05:30.003 回答
0

http://api.jqueryui.com/draggable/#option-snap Snap 是我一直在寻找的词,我将 snap 设置为 true 并且它有效,谢谢!

于 2013-10-11T08:15:41.780 回答