2011-01-27 133 views

回答

6

您也可以使用此:

http://jsfiddle.net/dtxhe/11/

代碼:

$("#container").resizable({ alsoResize: '#child' }); 
+0

+1,這是很好,乾淨。我們其他人正在複製jQuery UI已經提供的功能。 – Stephen 2011-01-27 21:22:08

2

您需要利用可調整大小的對象的resize事件。

http://jsfiddle.net/dtxhe/10/

$("#container").resizable({ 
    resize: function(event, ui) { 
     var parentwidth = $("#container").innerWidth(); 
     var parentheight = $("#container").innerHeight(); 
     $("#child").css({'width':parentwidth, 'height':parentheight}); 
    } 
}); 
+0

+1。看起來更好。 – Chandu 2011-01-27 21:17:23

1

可以改變孩子的大小在$ .resize事件,以適應父。 如(改變了代碼,減少jQuery選擇電話):

$("#container").resize(function(){ 
    var $this = $(this); 
    var parentwidth = $this.innerWidth(); 
    var parentheight = $this.innerHeight(); 
    $("#child").css({'width':parentwidth, 'height':parentheight}); 
}); 
$("#container").resizable(); 
$("#container").resize(); 

工作例如:http://jsfiddle.net/Chandu/dtxhe/9/