如何在不破坏子可调整大小的情况下销毁可调整大小的jQuery? [英] How do I destroy a jquery resizable without destroying child resizables?

查看:111
本文介绍了如何在不破坏子可调整大小的情况下销毁可调整大小的jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可调整大小的父div(仅宽度)-在此div中,我还有许多其他可调整大小的div(仅高度).

I have a parent div which is resizable (width only) - within this div I have a number of other divs that are also resizable (height only).

有时,我想禁用或破坏父级宽度的大小调整,而将内部高度的大小保留在适当的位置.

At times I want to either disable or destroy the parent width resizing but leave the inner height resizing in place.

当我调用$("#idTopDiv").resizable("destroy");时,这也会破坏所有子div上的可调整大小.

When I call $("#idTopDiv").resizable("destroy");, this destroys the resizables on all of the child divs as well.

典型的布局是:-

<div id=idDivTop> <!-- Resizable width -->
    <div id=idInnerOne>
    </div>

    <div id=idInnerTwo> <!-- Resizable height -->
    <div>
</div>

赞赏任何想法.

推荐答案

我认为发生这种情况是因为可调整大小的破坏会删除ui元素内部的所有调整大小的手形,而这些元素恰好包括内部可调整大小的调整大小句柄.因此,内部可调整大小实际上并没有被破坏,只是被弄乱了.

I think this happens because the destroy of resizable removes all resize handels inside of the ui element, which happens to include the resize handles for the inside resizables. So the inside resizables aren't actually being destroyed, they're just getting messed up.

您可以在此处看到可调整大小的源代码. >;它发生在第199行,显示为.find('.ui-resizable-handle').remove();.

You can see the Resizable source code here; its happening at line 199 where it says .find('.ui-resizable-handle').remove();.

要解决此问题,您还需要在内部可调整大小的对象上调用destroy方法,然后重新创建它们. ( jsfiddle )

To fix this you need to call the destroy method on the inner resizables also and then recreate them. (jsfiddle)

$("div").resizable();

// Destroy all three resizables
$("div").resizable("destroy");

// Recreate the inner resizables
$("#idInnerOne, #idInnerTwo").resizable();

您需要执行此操作,以删除在创建时可调整大小的设置的绑定和数据,否则当您尝试重新创建它时,它会认为它已经创建,并且不会执行任何操作.

You need to do that to remove bindings and data that resizable sets up upon creation, otherwise it will think its already created when you try re-creating it and it will do nothing.

您也可以考虑禁用外部可调整大小而不是破坏它,但是有其自身的问题.

You might also consider disabling the outer resizable instead of destroying it, but that has its own issues.

这篇关于如何在不破坏子可调整大小的情况下销毁可调整大小的jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆