如何从另一个事件触发jquery调整大小

How to trigger jquery resizable from another event

本文关键字:jquery 调整 另一个 事件      更新时间:2023-09-26

我有一个可调整大小的窗口:

$(".question-case-story").resizable( 
                                    {   handles:{'s': handle },
                                        alsoResize: ".question-case-inner",
                                        //minHeight: #,
                                        //maxHeight: #,
                                        maxHeight: $(".question-case-story").height(),
                                        resize: function (event, $this) { $(this).css({left:'inherit', top:'inherit'}); }
                                    });

当我点击按钮在其他地方做一些事情时,我想让这个调整大小自动发生,但是到一个特定的高度(窗口高度)。我该怎么做呢?

我发现了一个类似的问题,但它没有解决如何设置任何细节:如何触发jquery Resizable resize编程?

这里也是一样:http://forum.jquery.com/topic/triggering-resize-event-set-by-resizable

我运行jQuery UI v. 1.9.2

更新:我不能只是"设置"新的高度($(thing).css('height', whatever)),因为有其他的东西在div内部与可调整大小的功能交互

应该可以了:

var manresize=false;//Variable declared in a global scope    
$('#buttonid').click(function(){
    manresize=true;
    $(".question-case-story").trigger('resize');
});

现在需要创建一个自定义事件,例如manualresize

然后将该事件的监听器附加到$(".question-case-story")对象

$(".question-case-story").bind('manualresize',function(){
    //Same code that would run in the .resizable() 
    //method with a resize event trigger
});

复制/使用resize事件调用的.resizable()小部件的代码(不是100%确定这一点,但我认为jQuery可悲地不使用prototype)在您的自定义事件

在你的$(".question-case-story")对象:

resize: function (event, $this) { 
            $(this).css({left:'inherit', top:'inherit'});
            if(manresize/*var set on manual trigger*/){$(this).trigger("manualresize");manresize=false;}
        }

如果我理解正确,你只是想元素的大小调整,然后尝试:

$('#button').on('click', function(){
    $('.question-case-story').width(somevalue);
    $('.question-case-story').height($(window).height());
}