首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JQuery可调整大小的拆分器异常行为

JQuery可调整大小的拆分器异常行为
EN

Stack Overflow用户
提问于 2018-08-06 11:39:08
回答 1查看 381关注 0票数 0

我使用过Jquery可调整大小的组件,在父div中有三个可调整大小的div。我需要适当地调整所有三个div的大小,但是右边的面板和拆分器有问题。当您尝试调整大小时,它将以另一种方式移动。我一直在努力寻找解决这个问题的办法,但什么也想不出来。

JSFiddle

代码语言:javascript
运行
复制
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RickStrahl/jquery-resizable/master/src/jquery-resizable.js"></script>

<div class="page-container">
  <div class="panel-container">

    <div class="panel-left">
      left panel
    </div>

    <div class="splitter">
    </div>

    <div class="panel-center">
      center panel
    </div>

    <div class="splitter-right">
    </div>

    <div class="panel-right">
      right panel
    </div>


  </div>


</div>

Jquery

代码语言:javascript
运行
复制
$(".panel-left").resizable({
   handleSelector: ".splitter",
   resizeHeight: false
 });

  $(".panel-right").resizable({
   handleSelector: ".splitter-right",
   resizeHeight: false
 });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-06 13:05:17

这是一个有效的演示。我对你的CSS和JS做了修改。我使用JS创建了拆分器,并添加了onDragStart函数来处理它

代码语言:javascript
运行
复制
$(".panel-left,.panel-center")
     .css({
    /* required to allow resizer embedding */
    position: "relative"
  })
  /* check .resizer CSS */
  .prepend("<div class='resizer'></div>")
  .resizable({
    resizeHeight: false,
    // we use the column as handle and filter
    // by the contained .resizer element
    handleSelector: "",
    onDragStart: function(e, $el, opt) {
      // only drag resizer
      if (!$(e.target).hasClass("resizer"))
        return false;
      return true;
    }
 });
代码语言:javascript
运行
复制
html,
body {
  height: 100%;
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  padding: 0;
  margin: 0;
  overflow: auto;
}

.page-container {
  margin: 20px;
}

/* horizontal panel*/

.panel-container {
  display: flex;
  flex-direction: row;
  border: 1px solid silver;
  overflow: hidden;
  /* avoid browser level touch actions */
  xtouch-action: none;
}

.panel-left {
  flex: 0 0 auto;
  /* only manually resize */
  padding: 10px;
  width: 30%;
  min-height: 200px;
  white-space: nowrap;
  background: #838383;
  color: white;
}
.resizer {
    position: absolute;
    top: 0;
    right: 0px;
    bottom: 0;
    left: auto;
    width: 16px;
    cursor: col-resize;
    background: url(https://raw.githubusercontent.com/RickStrahl/jquery-resizable/master/assets/vsizegrip.png) center center no-repeat #535353;
}

.panel-center {
  flex: 1 1 auto;
  /* resizable */
  padding: 10px;
  width: 30%;
  min-height: 200px;
  background: #eee;
}

.panel-right {
  flex: 1 1 auto;
  /* resizable */
  padding: 10px;
  width: 30%;
  min-height: 200px;
  background: #eee;
}
代码语言:javascript
运行
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RickStrahl/jquery-resizable/master/src/jquery-resizable.js"></script>

<div class="page-container">
  <div class="panel-container">

    <div class="panel-left">
      left panel
    </div>

    <div class="panel-center">
      center panel
    </div>
    
    <div class="panel-right">
      right panel
    </div>


  </div>


</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51700275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档