可调整大小的样式左右箭头

时间:2019-02-28 08:27:12

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

我正在尝试向可调整大小的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>

1 个答案:

答案 0 :(得分:1)

不要给.resizer.right left: 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>