2013-06-19 22 views
1

我有一個窗口,是可調整大小觸發jQuery的調整大小:如何從另一個事件

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

當我點擊按鈕,在其他地方做一些事情,我想造成這種調整大小自動發生,而是一個特定的高度(窗口高度)。我怎樣才能做到這一點?

我發現了一個類似的問題,但它並沒有解決如何設置任何細節:How to trigger jquery Resizable resize programmatically?

同樣的事情在這裏:http://forum.jquery.com/topic/triggering-resize-event-set-by-resizable

我運行jQuery UI的v 1.9.2

更新:我不能只是「設置」新的高度($(thing).css('height', whatever)),因爲在該div內還有其他事情正在與可調整大小的功能進行交互。

+0

看看http://api.jquery.com/resize/ – Jacob

回答

1

應該這樣做:

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

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

現在你需要create a custom event稱爲manualresize例如。

然後你附上事件的監聽到你$(".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;} 
     } 
+0

我發佈這個問題之前嘗試這樣做,它什麼也沒做。沒有錯誤。沒有調整大小。根本不值一提。你能解釋它應該如何工作嗎?例如,如果它確實有效,它將調整到什麼尺寸? – emersonthis

+0

它應該簡單地觸發目標對象上的resize事件。你的代碼的工作方式應該是'$(this).css({left:'inherit',top:'inherit'});',不會有任何「調整大小」,只有'left'和'頂端CSS屬性會改變。我會建議使用瀏覽器日誌來查明事件是否被觸發。我沒有在過去的特定方法有任何問題... – PhilTrep

+0

我還是不太明白。你是說你發佈的代碼不應該被期望導致高度在我的上下文中改變/調整大小?如果是這樣,那麼什麼工作?是因爲我的'調整大小:'回調?如果我添加了特定的高度屬性,它會使它工作嗎? – emersonthis

0

如果我理解正確,只是想和你的元素來調整,然後只是嘗試:

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