jQuery可拖动和可拖放定位
我使用的是jqueryui和jqueryjQuery可拖动和可拖放定位,jquery,jquery-ui,jquery-ui-droppable,jquery-draggable,Jquery,Jquery Ui,Jquery Ui Droppable,Jquery Draggable,我使用的是jqueryui和jquerydraggable,我所有的draggable都使用jqueryclone帮助程序,并将draggable附加到dropable 这是我的密码 $('#squeezePage #droppable').droppable({ tolerance: 'fit', accept: '#squeezeWidgets .squeezeWidget', drop: function(event, ui) { var dropElem = ui.d
draggable
,我所有的draggable都使用jqueryclone帮助程序,并将draggable附加到dropable
这是我的密码
$('#squeezePage #droppable').droppable({
tolerance: 'fit',
accept: '#squeezeWidgets .squeezeWidget',
drop: function(event, ui) {
var dropElem = ui.draggable.html();
var clone = $(dropElem).clone();
clone.css('position', 'absolute');
clone.css('top', ui.absolutePosition.top);
clone.css('left', ui.absolutePosition.left);
$(this).append(clone);
$(this).find('.top').remove();
$(this).find('.widgetContent').slideDown('fast');
$(this).find('.widgetContent').draggable({
containment: '#squeezePage #droppable',
cursor: 'crosshair',
grid: [20, 20],
scroll: true,
snap: true,
snapMode: 'outer',
refreshPositions: true
});
$(this).find('.widgetContent').resizable({
maxWidth: 560,
minHeight: 60,
minWidth: 180,
grid: 20,
});
}
});
我正在用.css('top',ui.absolutePosition.top)设置克隆的位置代码>和css('left',ui.absolutePosition.left)代码>但位置是相对于车身的
该位置与可拖放位置无关,可拖放位置会随机下降。总的来说,可下拉和可拖动的集成并不紧密。我想让它更平滑。我得到body的偏移量,然后从widget克隆的偏移量中减去它
clone.css('top', ui.position.top - droppableOffset.top);
clone.css('left', ui.position.left - droppableOffset.left);
它起作用了 其中droppableOffset变量是jQuery(“#squeezePage#droppable”).offset();我花了很多时间寻找类似的解决方案。。非常感谢你。