javascript - Re-sizing a div should re-size other div's proportionately -


i have pasted js code, css , html respectively below.

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)            	newhgt = bsh - math.abs(diff);           else          	newhgt = bsh + diff;    	         $('#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>

the problem when re-size north handle of #foots div unable change height of #bodys div , #bodyc div while re-sizing , when re-size stops. need decrease top of #footc div re-sizing #foots div dynamically. sort of helpful.

below logic wrote re-size working #bodyc , #bodys accordingly.

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){      	var newfsh = ui.size.height;      	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 can 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>

and, added option called "ghost:true" jquery resizable widget.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -