我正在使用jQuery UI可调整大小和可拖动的函数。首先,我创建一个新元素,将其附加到body
并设置包含
function setDraggable(){
$div = $(document.createElement('div')).css({
//blah blah (tested and working perfectly)
});
$('body').append($div);
$('div#dragBox'). draggable({
containment : $div
}). resizable({
containment : $div
})
}
适用于draggable
,但不适用于resizable
答案 0 :(得分:0)
您可以使用解决方案https://jsfiddle.net/wx4r7kz6/
setDraggable = function(){
$div = $(document.createElement('div')).css({
//blah blah (tested and working perfectly)
'width': '100px',
'height': '100px',
'display': 'inline-block',
'border': '1px solid'
});
$div.attr("id", "dragBox");
$('body').append($div);
$('div#dragBox').draggable().resizable();
}
setDraggable();

<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
&#13;