0
我正在嘗試構建一個像jquery插件的任務欄。我正試圖在div中添加按鈕。當我有幾個可以放入父div的按鈕時,可以將按鈕大小設置爲默認按鈕大小。當新的按鈕要添加父div開始溢出,然後按鈕大小應調整大小,以適應父母。當它們再次被移除時,按鈕應該再次增加到它們的默認大小。這裏是我的代碼用jQuery隨時更改CSS顯示屬性並應用更改
_resizeChildren: function() {
var self = this; // this is the <div> holding the taskbar
var children = self.element.children();
var len = children.length;
var toolbarWidth = parseInt(self.element.width());
var totalMargin = parseInt(children.css('marginLeft')) + parseInt(children.css('marginRight'));
if (toolbarWidth/(len + totalMargin) >= $('#master').outerWidth()) //#master is a <div> holding the default size
{
self.element.css({'display': 'block'});
self.element.css({'tableLayout': ''});
children.css({'display': ''});
children.outerWidth(parseInt($('#master').outerWidth()));
}
else {
self.element.css({'display': 'table'});
self.element.css({'tableLayout': 'fixed'});
children.css({'display': 'table-cell'});
}
},
的問題是,當我運行這段代碼,當新的按鈕添加多達父div的寬度他們是單位的微細使用默認大小。當它們開始溢出時,舊的按鈕不會調整大小,因此留下很小的空間用於在非常薄的空間中向右擠壓的新按鈕。
你能提供一個http://jsfiddle.net鏈接 – shubendrak
那麼,如果你不能複製,我們也不能。不幸的是,我們在這種情況下幫不了多少忙 –