jQuery .resizable,如何为AlsoResize属性选择子级 [英] JQuery .resizable, how to select child for alsoResize property

查看:118
本文介绍了jQuery .resizable,如何为AlsoResize属性选择子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有弹出的窗口,可以拖动并调整大小.一切工作都很好,除了我需要调整窗口大小以在其中调整div的大小.可以通过设置alsoResize: 'selector'轻松实现,但是,此窗口的每个实例在其中具有相同的div和相同的类名.如果您调整一个窗口的大小,那么它将调整所有打开的窗口的内部div的大小.

I have windows that pop up and are draggable and resizable. Everything works great except that I need the resizing window to also resize a div within it. That is easily accomplished by setting alsoResize: 'selector' however, each instance of this window has the same div within it with the same class name. If you resize one window, it resizes the inner divs of ALL open windows.

$(chatWindow).draggable({ handle: '.dragHandle', containment: 'window', stack: '.chatWindow' })
    .resizable({ resize: function (event, ui) {
        api.reinitialise();
    },
        alsoResize: chatWindow + ' > .chatTerminal',
        start: function (event, ui) {
            var currentPosition = api.getContentPositionY();
            api.scrollToBottom();
            var maxPosition = api.getContentPositionY();
            api.scrollToY(currentPosition);
            var isAtBottom = (currentPosition == maxPosition);
            $(chatWindow).data('isAtBottom', isAtBottom);
        },
        stop: function (event, ui) {
            if ($(chatWindow).data('isAtBottom'))
                api.scrollToBottom();
        },
        minHeight: 125,
        minWidth: 250
    });

alsoResize: chatWindow + ' > .chatTerminal',不适用于选择子元素.我不能使用.find,因为AlsoResize仅采用选择器.显而易见的快速解决方案是将窗口名称(每个新窗口都唯一)附加到内部div,然后在内部div上使用id选择器.我只是好奇是否有更好的方法来固定子元素,而仅使用AlsoResize的选择器即可.

alsoResize: chatWindow + ' > .chatTerminal', doesn't work for selecting the child element. I can't use .find because alsoResize only takes a selector. The obvious quick solution would be to append the window name (which is unique for each new window) to the inner div and then use an id selector on the inner div. I am just curious if there is a better way to pin down a child element only using the selector for alsoResize.

推荐答案

var chatTerminal = '#' + channel + "_terminal";

alsoResize: chatTerminal

channel是主窗口的唯一ID,因此在创建窗口时,我只是将相同的唯一ID附加到子div上.然后,我可以只使用chatTerminal从AlsoResize选项中引用它.我列出了这个答案,以防没人回答,我会接受的.但是,如果您有更好的方法可以从选择器字符串中选择一个孩子,请告诉我:)

channel is the unique id of the main window, so I just appended that same unique id onto the child div when creating the window. Then I can just use chatTerminal to reference it from the alsoResize option. I am listing this answer in case nobody answers and I will accept it. However, if any of you have a better way to select a child from within a selector string, please tell me :)

这篇关于jQuery .resizable,如何为AlsoResize属性选择子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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