我有一個父div與子div內。父div使用jquery Ui可調整大小。當父div被調整大小時,如何實時生成父div的尺寸。jquery更改孩子deminsions匹配父母后調整大小
這裏就是我有 http://jsfiddle.net/dtxhe/7/
調整大小後,孩子的div不調整根據它的父。
我有一個父div與子div內。父div使用jquery Ui可調整大小。當父div被調整大小時,如何實時生成父div的尺寸。jquery更改孩子deminsions匹配父母后調整大小
這裏就是我有 http://jsfiddle.net/dtxhe/7/
調整大小後,孩子的div不調整根據它的父。
您需要利用可調整大小的對象的resize
事件。
$("#container").resizable({
resize: function(event, ui) {
var parentwidth = $("#container").innerWidth();
var parentheight = $("#container").innerHeight();
$("#child").css({'width':parentwidth, 'height':parentheight});
}
});
+1。看起來更好。 – Chandu 2011-01-27 21:17:23
可以改變孩子的大小在$ .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/bWMxm/2/
+1,這是很好,乾淨。我們其他人正在複製jQuery UI已經提供的功能。 – Stephen 2011-01-27 21:22:08