I want to re-size an element inside and outside of its parent without interruption. Please see the example.
I assume there are three <div>
rows and each row has several elements with similar (开发者_运维百科or different) css properties. E.g.:
element-1, element-2, ....... element-6
@Edit
inside resizable : please see in the pic. as i am resizing element-1
within `row-1' and the other siblings adjusted the width. i can do it by my own
outside resizable : please see the pic. element-1 is re-sized it's length without affecting any dimension of it's parent row-1
& siblings element-2
but it affect the others elements e.g. element-3 & 4
has adjusted the width for element-1
. This is what i wanted to ask & not able to do it.
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/
精彩评论