JQuery UI Draggable包含不适用

时间:2013-04-04 06:13:48

标签: javascript jquery jquery-ui

$("div.con_user").draggable({ 
        delay: 100,
        revert: true,
        containment: $(this).closest(".roomblock_content"), 
        start: function( event, ui) {
            $(this).css("z-index", "200");
        },
        stop: function( event, ui) {
            $(this).css("z-index","50");
        }
    });

JQuery UI的包含选项似乎被打破了。除非我克隆div.con_user并重新应用draggable,否则它似乎根本不尊重包含选项。

可能是因为我的页面中有很多.roomblock_content元素,或者因为我的draggable包含在droppable中?

编辑:抱歉,我忘记了HTML标记。这是:

<div class="roomblock_content">
    <div class="roomblock_col1">
        <div class="roomblock_pool_box">
            <span class="roomblock_pool_title"> Pool </span>

            <ul class="roomblock_slots">
                <li>
                    <div class="con_user prepaid_con"> </div>
                </li>
                <li>
                    <div class="con_user prepaid_con"> </div>
                </li>
            </ul>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

我认为你错误地设置了draggable的包含选项。它应该如下所示:

 containment: ".roomblock_content",

<强> DEMO

希望这适合你:)