这一切都运行得很好,现在我的需求改变了,我放入的.draaa项的div也必须是可调整的。因此,我将我的项目放在一个可丢弃和可调整大小的DIV中。
选项容器:' #GridDiv‘不再起作用了,但是当#GridDiv dident上有可调整的大小时,它就起作用了。因此,当我调整我的GridDiv的大小时,被拖放的元素也应该调整大小,但不能大于'#GridDiv‘。
有谁有主意吗?如果你浏览一下代码,你就会明白。
$(".draaa").draggable({
helper: 'clone',
stop: function(ui, event){
var stop = $(this).position();
$(this).attr('data-component-x', stop.left);
$(this).attr('data-component-y', stop.top);
}
});
$('#GridDiv').resizable();
$("#GridDiv").droppable({
accept: '.draaa',
drop: function(event, ui) {
i ++;
var getClone = $(ui.draggable).clone();
getClone.attr("id",i+"_"+getClone.attr('id'));
var hela_cid =getClone.attr("id");
var deladcid = hela_cid.split("_");
var cid = deladcid[2];
var stop = $(getClone).position();
var widthpx = getClone.css('width');
var heightpx = getClone.css('height');
var width = parseInt(widthpx, 10);
var height = parseInt(heightpx, 10);
var draggableDocumentOffset = ui.helper.offset();
var droppableDocumentOffset = $(this).offset();
var left = draggableDocumentOffset.left - droppableDocumentOffset.left;
var top = draggableDocumentOffset.top - droppableDocumentOffset.top;
getClone.css("left",left);
getClone.css("top", top);
getClone.css("position", "absolute");
$(this).append(getClone);
$("#GridDiv .draaa").addClass("item");
$(".item").removeClass("ui-draggable draaa");
$(".item").draggable({
containment: '#GridDiv',
//grid: [10,10],
stop: function(ui, event){
var stop = $(this).position();
$(this).attr('data-component-x', stop.left);
$(this).attr('data-component-y', stop.top);
},
}).resizable({
helper: "ui-resizable-helper",这样做是可行的
//containment: '#GridDiv', //maxHeight: parseInt(MaxHeight),
//maxHeight: 300,
stop: function(event, ui) {
var width = ui.size.width;
var height = ui.size.height;
$('#'+hela_cid).attr('data-component-width', width);
$('#'+hela_cid).attr('data-component-height', height);
}
});
}
});这一行被注释掉了。所以我可以将.draaa组件的大小调整到比父组件'#GridDiv‘更大,但我不想这样做。
发布于 2015-03-27 22:56:40
好了,我找到了为什么它不起作用:/
}).resizable({
//helper: "ui-resizable-helper",
containment: '#GridDiv',帮助器选项让它没有发生,为什么?我不知道。因此,我将不使用helper选项:)
https://stackoverflow.com/questions/29302821
复制相似问题