【问题标题】:Resizable style left and right arrows可调整大小的样式左右箭头
【发布时间】:2019-02-28 08:27:12
【问题描述】:

我正在尝试将左右两个圆圈添加到可调整大小的 div 并设置它们的样式。我添加了它们,看起来没问题,但是当我尝试从左到右调整大小时,圆圈在同一位置保持不变。这个想法是用可调整大小的 div 移动圆圈。你能帮帮我吗?

$("#resizable").resizable({
  containment: "#image-container-step2",
  handles: "e,w"
});
#resizable {
  background: red;
  position: absolute;
  height: 10px;
  width: 200px;
  top: 100px;
  /*left: 100px;*/
}

#resizable .resizers {
  width: 100%;
  height: 100%;
  border: 3px solid #4286f4;
  box-sizing: border-box;
}

#resizable .resizers .resizer {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: white;
  border: 3px solid #4286f4;
  position: absolute;
}

#resizable .resizers .resizer.left {
  left: -5px;
  top: -7px;
  cursor: w-resize;
  /*resizer cursor*/
}

#resizable .resizers .resizer.right {
  left: 190px;
  top: -7px;
  cursor: e-resize;
  /*resizer cursor*/
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" />
<div id="resizable">
  <div class='resizers'>
    <div class="resizer left"></div>
    <div class="resizer right"></div>
  </div>
</div>

【问题讨论】:

  • 您的 sn-p 缺少对 jQueryUI.js 的引用 - 这也是您的实际代码中的错误吗?
  • Noooo......我只放了一段html代码没有包含添加的库
  • 好的,我已经在 sn-p 中为您添加了对 jQueryUI 的引用。

标签: jquery css jquery-ui jquery-ui-resizable


【解决方案1】:

不要给.resizer.rightleft: 190px,而是给它right: -5px。现在,如果您调整大小,它将与行一致。希望对你有帮助

代码已更新,现在也可以用圆圈调整大小

$("#resizable").resizable({
  containment: "#resizable",
  handles: "e,w"
});
#resizable {
  background: red;
  position: absolute;
  height: 10px;
  width: 200px;
  top: 100px;
  /*left: 100px;*/
}

#resizable .resizers {
  width: 100%;
  height: 100%;
  border: 3px solid #4286f4;
  box-sizing: border-box;
}

#resizable .resizers .resizer {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: white;
  border: 3px solid #4286f4;
  position: absolute;
}
#resizable .ui-resizable-handle{
    width: 31px;
    height: 31px;
    top: 50%;
    transform: translateY(-50%);
}
#resizable .resizers .resizer.left,#resizable .resizers .resizer.right{
top:50%;
transform:translateY(-50%);
}
#resizable .resizers .resizer.left {
  left: -5px;
  cursor: w-resize;
  /*resizer cursor*/
}

#resizable .resizers .resizer.right {
  right: -5px;
  cursor: e-resize;
  /*resizer cursor*/
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" />
<div id="resizable">
  <div id="resizers" class='resizers'>
    <div class="resizer left"></div>
    <div class="resizer right"></div>
  </div>
</div>

【讨论】:

  • 不是整个圈子都是可拖动的,你有想法吗?
  • @HareaCostea 检查现在我更新了代码,现在圆圈可以拖动了。实际上在js上我没有更新id。
  • 还为句柄添加了一个 css,以便它覆盖圆圈并与圆圈一起使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-26
  • 2014-01-19
  • 2012-08-31
  • 1970-01-01
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多