我正在尝试使用具有绝对位置square divs的jquery可调整大小的处理程序
但是当我点击" north"和" west"按钮(仅此两个方向)并稍微拖动以调整大小,框本身变小1或2px
北处理程序中的,如(顶部:100px,高度:100px =>顶部:99px,高度:99px)
我做错了什么?
element.resizable({
minWidth: 1,
minHeight: 1,
handles:{
'n': '.ui-resizable-n',
'w': '.ui-resizable-w',
'e': '.ui-resizable-e',
's': '.ui-resizable-s'
}
})
此处a demo link!
当我拖着#34;守门员"项目到"屏幕"并且移动北调整大小处理程序,方块出问题答案 0 :(得分:2)
请将box-sizing: border-box;
更改为box-sizing: content-box;
。
https://jsfiddle.net/6h02cmvf/
$(document).ready(function() {
$('#container > .ui-element-libraries-container > .ui-element-container').draggable({
opacity: 0.5,
helper: "clone",
appendTo: '#full',
cursor: "move",
revert: true
})
$('#screen').droppable({
drop: (event,ui)=>{
let layoutOffset=$('#screen').offset()
let element=ui.helper.clone().css({
'position': 'absolute',
'opacity': 1,
'left': (ui.position.left-layoutOffset.left)+'px',
'top': (ui.position.top-layoutOffset.top)+'px',
})
element.toggleClass('ui-element-container ui-element')
element.empty()
element.append("<div class='ui-resizable-handle ui-resizable-n'></div>")
element.append("<div class='ui-resizable-handle ui-resizable-s'></div>")
element.append("<div class='ui-resizable-handle ui-resizable-e'></div>")
element.append("<div class='ui-resizable-handle ui-resizable-w'></div>")
element.appendTo('#screen')
element.resizable({
minWidth: 1,
minHeight: 1,
handles:{
'n': '.ui-resizable-n',
'w': '.ui-resizable-w',
'e': '.ui-resizable-e',
's': '.ui-resizable-s'
}
})
ui.helper.remove()
}
})
})
.pane{
color: black;
background-color: white;
position: absolute;
display: block;
overflow: hidden;
border: 2px solid black;
}
#container{
margin: 0px;
left: 300px;
right: auto;
top: 0px;
bottom: 0px;
width: 300px;
height: 500px;
}
#screen{
margin: 0px;
left: 0px;
right: auto;
top: 0px;
bottom: 0px;
width: 300px;
height: 500px;
}
.ui-element-libraries-container{
width:100%;
}
.ui-element-container{
color: black;
background-color: yellow;
border: 1px solid black;
margin-left: -1px;
margin-top: -1px;
width: 33.3%;
min-width: 80px;
max-width: 90px;
height: 100px;
box-sizing: border-box;
text-align: center;
line-height: 12px;
float:left;
font-size: 11px;
position: relative;
overflow: hidden;
cursor: move;
}
.ui-element{
color: black;
background-color: white;
border: 1px solid black;
margin-left: -1px;
margin-top: -1px;
width: 100px;
height: 100px;
box-sizing: content-box;
text-align: center;
line-height: 12px;
float:left;
font-size: 11px;
position: relative;
cursor: move;
}
.ui-resizable-handle{
position: absolute;
width: 7px;
height: 7px;
border: 1px solid blue;
background: white;
display: block;
}
.ui-resizable-n{
top: -4px;
bottom: auto;
left: 50%;
right: auto;
margin-left: -4px;
cursor: ns-resize;
}
.ui-resizable-s{
top: auto;
bottom: -4px;
left: 50%;
right: auto;
margin-left: -4px;
cursor: ns-resize;
}
.ui-resizable-e{
top: 50%;
bottom: auto;
left: auto;
right: -4px;
margin-top: -4px;
cursor: ew-resize;
}
.ui-resizable-w{
top: 50%;
bottom: auto;
left: -4px;
right: auto;
margin-top: -4px;
cursor: ew-resize;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<div id="full">
<div id="screen" class="pane">
screen
</div>
<div id="container" class="pane">
keeper
<div class="ui-element-libraries-container">
<div class="ui-element-container">
<div>
b
</div>
</div>
</div>
</div>
</div>