Вы можете поиграть с этим примером. Сначала нажмите кнопку «Новый контейнер», затем кнопку «Новая ячейка внутри контейнера». Вы можете перетаскивать контейнер, а также ячейки внутри него.
JavaScript:
var instanceRegistry = [];
var containerRegistry = [];
var cellRegistry = [];
$(function() {
var endpointOptions = {
isSource: true,
isTarget: true
};
$('#newContainerButton').click(newContainer);
$('#newCellButton').click(newCell);
function newContainer() {
var containerIndex = "container" + (containerRegistry.length + 1);
$('#containerTemplate').clone().appendTo('#mainContainer')
.show()
.attr('id', containerIndex)
.draggable({
containment: 'mainContainer',
cursor: 'move'
})
.find('.newCellButton').click(newCell).end();
containerRegistry.push(containerIndex);
var containerInstance = jsPlumb.getInstance({
Container: containerIndex,
Endpoint: [ // The default Endpoint definition.
'Dot', // Endpoint type
{ // Endpoint type options
radius: 6, // Defines the radius of the dot
cssClass: 'cell-endpoint' // A CSS class to attach to the element the Endpoint creates
}
],
PaintStyle: { // The default appearance of a Connector
strokeStyle: '#2e6f9a', // color for a Connector
lineWidth: 2 // width of a Connector's line
}
});
instanceRegistry.push(containerInstance);
}
function newCell(event) {
var $container = $(event.target).parent();
var cellIndex = "cell" + (cellRegistry.length + 1);
$('#cellTemplate').clone().appendTo($container)
.show()
.attr('id', cellIndex);
cellRegistry.push(cellIndex);
var num = containerRegistry.indexOf($container.attr('id'));
var instance = instanceRegistry[num];
instance.draggable(cellIndex, {
containment: $container,
cursor: 'move'
});
instance.addEndpoint(cellIndex, {anchor: "Top"}, endpointOptions);
instance.addEndpoint(cellIndex, {anchor: "Right"}, endpointOptions);
instance.addEndpoint(cellIndex, {anchor: "Bottom"}, endpointOptions);
instance.addEndpoint(cellIndex, {anchor: "Left"}, endpointOptions);
}
});
person
alemv
schedule
21.04.2015