3

You can add containment dynamically like this:

$(this).draggable( "option", "containment", "parent" );

How do i remove the containment again? Like:

$(this).draggable( "option", "containment", "none" );

except that doesn't work.. I could not find any methods for it in the API documentation

EDIT: I want to be able to drag the item but with no containment. I am using this with checkboxes:

        var denne = $(this);
        if ($('#containment').is(':checked')) {
            $(this).draggable( "option", "containment", "parent" );
        }
        $("#containment").each(function(){
            if ($(this).prop('checked')==false){ 
                denne.draggable( "option", "containment", false );
            }
        });
4

1 回答 1

1

取决于你想做什么...

您可以“禁用”该元素,使其不再可拖动。

$(this).draggable( "option", "disabled", true );

或者您可以更改包含边界,以便可以将元素拖动到原始约束之外。

$(this).draggable( "option", "containment", "window" );

或者通过指定确切的边界。

$(this).draggable( "option", "containment", [x1, y1, x2, y2] );

或者正如 Menencia 在评论中提到的那样,您可以尝试将遏制设置为 false

$(this).draggable( "option", "containment", false );
于 2013-04-25T13:56:07.047 回答