2011-01-27 146 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/