2

我想在其父元素内部和外部重新调整元素的大小而不会中断。请参阅示例

我假设有<div>三行,每行都有几个具有相似(或不同)css 属性的元素。例如:

element-1, element-2, ....... element-6

@Edit inside resizable :请看图片。当我element-1在“row-1”内调整大小时,其他兄弟姐妹调整了宽度。我可以自己做 在此处输入图像描述

外部可调整大小:请看图片。row-1element-1 重新调整了它的长度,而不影响它的父级和兄弟级的任何尺寸,element-2但它影响其他元素,例如element-3 & 4调整了element-1. 这就是我想问但无法做到的。在此处输入图像描述

4

1 回答 1

0

There is no straightforward way to achieve that result. You have to alter CSS (add the following):

.row {
    position: relative;
}
.element {
    position: absolute;
    /*Remove the float attribute, which is obsolete*/
}

The JavaScript code has also to be altered:

$(function(){
    var zIndex = 100;
    $('.element').mouseover(function(){
        var originalHeight = $(this).height();
        $(this).resizable({start: function() {
                   $(this).css('z-index', ++zIndex);
        }, stop: function(){
            /*Horizontal fix*/
            var nxt = $(this).nextAll();
            var width = $(this).position().left + $(this).width();
            var safeWidth = width;
            var root = $(this).parent();
            var thisheight = $(this).height();
            var height = root.height();
            for(var i=0,l=nxt.length;i<l;i++){
                $(nxt[i]).css("left", width+"px");
                width += $(nxt[i]).width();
                if($(nxt[i]).height() > height) safeWidth = width;
            }
            /*Vertical fix*/
            if(thisheight > height || originalHeight > thisheight){
                var nxt = root.nextAll();
                for(var i=0, l=nxt.length; i<l; i++){
                    var tht = nxt[i];
                    if(height >= thisheight){
                        width = 0;
                    } else {
                        width = safeWidth;
                    }
                    height += $(tht).height();
                    if(!/(^|\s)row(\s|$)/.test(tht.className)){
                        continue;
                    }
                    var in_nxt = $(tht).children();
                    for(var j=0,k=in_nxt.length; j<k; j++){
                        $(in_nxt[j]).css("left", width+"px");
                        width += $(in_nxt[j]).width();
                    }
                }
            }
            originalHeight = thisheight;
        }});
       });
    $('.element').each(function(){
        var ths = $(this).prevAll();
        var width = 0;
        for(var i=0,l=ths.length;i<l;i++)width+=$(ths[i]).width();
        $(this).css("left", width+"px")});
});

Preview: http://jsfiddle.net/cQFzf/12/

于 2011-09-16T10:33:31.257 回答