我正在尝试向可调整大小的 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>
最佳答案
不是给 .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>
关于jquery - 可调整大小的左右箭头样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54921285/