1

I have a window that is resizable:

$(".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'}); }
                                    });

When I click button to do something elsewhere, I want to cause this resize to happen automatically, but to a specific height (the window height). How can I do this?

I found a similar question, but it doesn't address how to set any specifics: How to trigger jquery Resizable resize programmatically?

Same thing here: http://forum.jquery.com/topic/triggering-resize-event-set-by-resizable

I'm running jQuery UI v. 1.9.2

Update: I can't just "set" the new height ($(thing).css('height', whatever)) because there are other things going on inside that div that interact with the resizable functionality.

4

2 回答 2

1

那应该这样做:

var manresize=false;//Variable declared in a global scope    

$('#buttonid').click(function(){
    manresize=true;
    $(".question-case-story").trigger('resize');
});

现在您需要创建一个名为manualresizeexample 的自定义事件。

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

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

在您的自定义事件中复制/使用事件调用的.resizable()小部件中的代码resize(对此不是 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;}
        }
于 2013-06-19T16:15:41.053 回答
0

如果我理解正确,并且您只想调整元素大小,那么请尝试:

$('#button').on('click', function(){
    $('.question-case-story').width(somevalue);
    $('.question-case-story').height($(window).height());
}
于 2013-06-19T16:20:44.077 回答