最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to resize two divs side by side like windows explorer - Stack Overflow

programmeradmin1浏览0评论

Hi I must create a page that RightCol must be resizable like windows explorer window. The size of each column must equal to the height of the browser. By resizing the browser, these two column must be resized.

My code don't work correctly. could an one help me , please?

/**jquery :**/

$("#LeftCol").resizable({
  maxHeight: 250,
  maxWidth: 900,
  minHeight: 150,
  minWidth: 200
});

$('#LeftCol').resize(function () {
  $('#RightCol').width($("#parent").width() - $("#LeftCol").width());
});
$(window).resize(function () {
  $('#RightCol').width($("#parent").width() - $("#LeftCol").width());
  $('#LeftCol').height($("#parent").height());
});
<link href=".12.0/themes/smoothness/jquery-ui.css" rel="stylesheet" />
#parent {
  position: relative;
  min-height: 300px;
  margin: 0;
  padding: 0;
  width: 100%;
}

#LeftCol {
  position: relative;
  float: right;
  min-height: 400px;
  width: 65%;
  background-color: #A2A;
  overflow:auto;
}

#RightCol {
  position: relative;
  float: right;
  min-height: 400px;
  width: 35%;
  background-color: #BBB;
  overflow:auto;
  max-height:300px;
}
<script src=".1.1/jquery.min.js"></script>
<script src=".12.1/jquery-ui.min.js"></script>
<div id="parent">
  <div id="RightCol"></div>
  <div id="LeftCol"></div>
</div>

Hi I must create a page that RightCol must be resizable like windows explorer window. The size of each column must equal to the height of the browser. By resizing the browser, these two column must be resized.

My code don't work correctly. could an one help me , please?

/**jquery :**/

$("#LeftCol").resizable({
  maxHeight: 250,
  maxWidth: 900,
  minHeight: 150,
  minWidth: 200
});

$('#LeftCol').resize(function () {
  $('#RightCol').width($("#parent").width() - $("#LeftCol").width());
});
$(window).resize(function () {
  $('#RightCol').width($("#parent").width() - $("#LeftCol").width());
  $('#LeftCol').height($("#parent").height());
});
<link href="https://code.jquery./ui/1.12.0/themes/smoothness/jquery-ui.css" rel="stylesheet" />
#parent {
  position: relative;
  min-height: 300px;
  margin: 0;
  padding: 0;
  width: 100%;
}

#LeftCol {
  position: relative;
  float: right;
  min-height: 400px;
  width: 65%;
  background-color: #A2A;
  overflow:auto;
}

#RightCol {
  position: relative;
  float: right;
  min-height: 400px;
  width: 35%;
  background-color: #BBB;
  overflow:auto;
  max-height:300px;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery./ui/1.12.1/jquery-ui.min.js"></script>
<div id="parent">
  <div id="RightCol"></div>
  <div id="LeftCol"></div>
</div>

Share Improve this question edited Sep 25, 2019 at 7:17 Farzaneh Talebi asked Nov 25, 2015 at 7:54 Farzaneh TalebiFarzaneh Talebi 9254 gold badges26 silver badges48 bronze badges 7
  • what browsers does it need to work in? You might take a look at flex box if you don't need a high degree of backwards patibility. – thelastshadow Commented Nov 25, 2015 at 7:56
  • modern browser , and ie9 . – Farzaneh Talebi Commented Nov 25, 2015 at 7:58
  • jQuery IS NOT a language, or a standard. It's a library - a tool. Your "code" is written in JavaScript. – Amit Commented Nov 25, 2015 at 7:58
  • Alas ie9 doesn't support flexbox. – thelastshadow Commented Nov 25, 2015 at 8:00
  • if ie10 support it , i can ignor ie9. – Farzaneh Talebi Commented Nov 25, 2015 at 8:03
 |  Show 2 more ments

3 Answers 3

Reset to default 3

I would set one to be resizable and the other one to be a flexbox.

https://codepen.io/anon/pen/YjJBZm

I took one of the answers already given and tried it out in this pen. Some adjustments were made.

HTML

#parent {
  display: flex;
  border: 1px solid #000;
  height: 75vh;
  width: 100%;
}

#LeftCol {
  flex-grow: 1;
  border: 1px solid red;
  resize: horizontal;
  overflow: auto;
}

#RightCol {
  flex-grow: 3;
  border: 1px solid red;
}
<div id="parent">
  <div id="LeftCol">LeftCol</div>
  <div id="RightCol">RightCol</div>
</div>

Solution using pure css Flexbox Layout http://codepen.io/gmrash/pen/epaqva

#parent {
  display: flex;
  border: 1px solid #000;
  height: 100vh;
}

#LeftCol {
  flex-grow: 3;
  border: 1px solid red;
}

#RightCol {
  flex-grow: 1;
  border: 1px solid red;
}
<div id="parent">
  <div id="LeftCol">LeftCol</div>
  <div id="RightCol">RightCol</div>
</div>

I faced the same challenge and the most effective way to solve it was through the library Jquery UI. Here's how : As of right now, here are the CDN links (of course you can check online for the lastest link) :

<link
  rel="stylesheet"
  href="https://cdnjs.cloudflare./ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css"
  integrity="sha512-ELV+xyi8IhEApPS/pSj66+Jiw+sOT1Mqkzlh8ExXihe4zfqbWkxPRi8wptXIO9g73FSlhmquFlUOuMSoXz5IRw=="
  crossorigin="anonymous"
  referrerpolicy="no-referrer"
/>
<script 
  src="https://cdnjs.cloudflare./ajax/libs/jqueryui/1.13.2/jquery-ui.min.js" 
  integrity="sha512-57oZ/vW8ANMjR/KQ6Be9v/+/h6bq9/l3f0Oc7vn6qMqyhvPd1cvKBRWWpzu0QoneImqr2SkmO4MSqU+RpHom3Q==" 
  crossorigin="anonymous" 
  referrerpolicy="no-referrer">
</script>

the 2 Divs :

    .resizable-container {
      display: flex;
    }

    .resizable, 
    .resizable2 {
      border: 1px solid #ccc;
      margin: 5px;
      padding: 10px;
    }
<div class="resizable-container">
    <div class="resizable"> Div 1 Content</div>
    <div class="resizable2"> Div 2 Content</div>
</div>

And the js code :

    $(document).ready(function () {
  $(".resizable").resizable({
    handles: "e", // Permet le redimensionnement uniquement à partir du bord droit
    minWidth: 100, // Taille minimal!e
    resize: function (event, ui) {
      var parentWidth = $(this).parent().width();
      var resizable2Width = parentWidth - ui.size.width;
      $(".resizable2").width(resizable2Width);
    },
  });
});

the callback function is triggered while the user is resizing the div .resizable ; it dynamically ajusts the width of the div .resizable2 in the process.

For more info you can check the documentation at jqueryui.

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>