Changes

Jump to navigation Jump to search
696 bytes added ,  17:24, 5 August 2021
jQuery UI Dragging Test 2
Line 24: Line 24:  
e.preventDefault();
 
e.preventDefault();
 
$(this).css("background-image", 'url(' + ')');
 
$(this).css("background-image", 'url(' + ')');
 +
});
 +
 +
jQuery.fn.swap = function(b){
 +
b = jQuery(b)[0];
 +
var a = this[0];
 +
var t = a.parentNode.insertBefore(document.createTextNode(''), a);
 +
b.parentNode.insertBefore(a, b);
 +
t.parentNode.insertBefore(b, t);
 +
t.parentNode.removeChild(t);
 +
return this;
 +
};
 +
 +
$( "#wagon-configurator li.wagon-slot" ).draggable({helper: "clone"});
 +
$( "#wagon-configurator li.wagon-slot" ).droppable({
 +
accept: "#wagon-configurator li.wagon-slot",
 +
activeClass: "ui-state-hover",
 +
hoverClass: "ui-state-active",
 +
drop: function(event, ui){
 +
var draggable = ui.draggable, droppable = $(this),
 +
dragPos = draggable.position(), dropPos = droppable.position();
 +
draggable.swap(droppable);
 +
}
 
});
 
});
 
});
 
});

Navigation menu