2016-03-31 22 views
0

私はそれぞれJSコード、CSS、HTMLを貼り付けています。divのサイズを変更すると、他のdivのサイズを変更する必要があります

var hgt=0,newhgt=0,bsh=0,diff=0; 
 

 
$('#footS').resizable({ 
 
    alsoResize:"#footC", 
 
    handles:"n", 
 
    start: function(event,ui){ 
 
     oldhgt = ui.size.height; 
 
     bsh = $('#bodyS').height(); 
 
    }, resize:function(event,ui){ 
 
     diff = oldhgt - ui.size.height; 
 
     if(diff<0) 
 
      \t newhgt = bsh - Math.abs(diff); 
 
     else 
 
     \t newhgt = bsh + diff; 
 
    \t 
 
     $('#bodyS').height(newhgt); 
 
    }, stop:function(event,ui){ 
 
    newhgt = bsh - Math.abs(oldhgt - ui.size.height); 
 
    $('#bodyS').css("height",newhgt+"px"); 
 
    $('#bodyC').css("height",newhgt+"px"); 
 
    $('#footS').css("height",ui.size.height+"px"); 
 
    } 
 
});
#vscale,#canvas { 
 
     height: auto; 
 
     width: auto; 
 
     /* border: 1px solid gray; */ 
 
     margin-left: 5px; 
 
     float: left; 
 
     position:absolute; 
 
} 
 
#canvas{ 
 
    margin-left:100px; 
 
} 
 
.scale { 
 
height:150px; 
 
width:50px; 
 
border: 1px dotted gray; 
 
} 
 
#headS,#headC{border-color: red;min-height:50px;} 
 
#bodyS,#bodyC{border-color: blue;min-height:50px;} 
 
#footS,#footC{border-color: green; min-height:50px;} 
 
.ui-resizable-helper { 
 
    border: 1px dotted #999; 
 
} 
 
.fscale{top:0.0px;position:relative;} 
 

 
.cont{ 
 
    border: 1px dotted gray; 
 
    height:150px; 
 
    width:auto; 
 
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/> 
 
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
 
<script src="https://code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> 
 
<div id="vscale" style="top:75px;"> 
 
    <div id="headS" class="scale">HScale</div> 
 
    <div id="bodyS" class="scale">BScale</div> 
 
    <div id="footS" class="scale fscale">FScale</div> 
 
</div> 
 
<div id="canvas" style="width:300px;top:75px;"> 
 
    <div id="headC" class="cont">HeadContainer</div> 
 
    <div id="bodyC" class="cont">BodyContainer</div> 
 
    <div id="footC" class="cont">FootContainer</div> 
 
</div>

問題は、私が再サイズは、私も#bodySのdiv要素の高さと#bodyC divの中に再サイズなどを変更することができません#footSのdiv要素の北ハンドルですre-sizeが停止したとき。 #footS divのサイズを動的に変更しているので、#footC divの上部を小さくする必要もあります。どんな種類の助けが役に立つでしょう。

+1

申し訳ありませんが、あなたが達成しようとしていることはわかりません。私はJSFiddleでそれを実行して何が起こっているのかを視覚化しましたが、私はまだ分かりません。 (これもjQueryです) – JackHasaKeyboard

+0

北のハンドルを#footSから上にドラッグすると、サイズ変更中に#FootC、#bodyC、および#bodySの高さを動的に変更し、サイズ変更が停止したときにそれらを設定する必要があります。 – TheGaME

+0

私はあなたがテーブルと呼ばれるものを探していると信じています。あなたが達成しようとしているものの論理を扱うでしょう。テーブルは、高さと幅が均一に制限されている「セル」と呼ばれる要素で構成されるグリッドです。 Microsoft Excelを考えてみましょう。 https://jsfiddle.net/5jp06gn2/のように、テーブルの列と行、およびそれらに含まれるすべての要素が自動的に再構成される方法を参照してください。 – JackHasaKeyboard

答えて

0

以下は、#bodyCと#bodySのリサイズサイズを取得するために書いたロジックです。

var oldFSH=0,newBSH,oldBSH=0,diff; 
 
$('#footS').resizable({ 
 
    ghost:true, 
 
    handles:"n", 
 
    start: function(event,ui){ 
 
     oldFSH = $('#footS').height(); 
 
     oldBSH = $('#bodyS').height(); 
 
     newBSH=diff=0; 
 
     
 
    }, resize:function(event,ui){ 
 
    \t var newFSH = ui.size.height; 
 
    \t diff = oldFSH > newFSH?oldFSH - newFSH:newFSH - oldFSH; 
 
     newBSH = oldFSH > newFSH?oldBSH+diff:oldBSH-diff; 
 
     $('#bodyS,#bodyC').height(newBSH); 
 
     
 
    }, stop:function(event,ui){ 
 
     var newFSH = ui.size.height; 
 
     $('#bodyS,#bodyC').css("height",newBSH+"px"); 
 
     $('#footC').css("height",newFSH + "px"); 
 
     $("#footS").css("top","0px"); 
 
    } 
 
});
#vscale,#canvas { 
 
     height: auto; 
 
     width: auto; 
 
     /* border: 1px solid gray; */ 
 
     margin-left: 5px; 
 
     float: left; /*Here you can also use display: inline-block instead of float:left*/ 
 
     position:absolute; 
 
} 
 
#canvas{ 
 
    margin-left:100px; 
 
} 
 
.scalecont { 
 
height:144px; 
 
border: 1px dotted gray; 
 
} 
 

 
.bodycss{ 
 
height:200px; 
 
border: 1px dotted blue; 
 
} 
 

 
#footS{top:0px;position:relative;} 
 

 
#headC,#bodyC,#footC{width:auto;} 
 

 
.ui-resizable-helper { 
 
    border: 1px dotted #999; 
 
}
<div id="vscale" style="top:100px;"> 
 
    <div id="headS" class="scalecont">HScale</div> 
 
    <div id="bodyS" class="bodycss">BScale</div> 
 
    <div id="footS" class="scalecont">FScale</div> 
 
</div> 
 
<div id="canvas" style="width:300px;top:100px;"> 
 
    <div id="headC" class="scalecont">HeadContainer</div> 
 
    <div id="bodyC" class="bodycss">BodyContainer</div> 
 
    <div id="footC" class="scalecont">FootContainer</div> 
 
</div>

そして、また、私は "ゴースト:真" と呼ばれるオプションを追加jqueryのサイズ変更可能なウィジェットに。

関連する問題