JQuery UI Draggable: Stack on Click

Is it possible to trigger a stack routine draggable

on push rather than just drag and drop?

I found this solution, which is basically trying to just copy the library code. (Also missing an important part that I pasted in below). Isn't there a more elegant solution?

By changing the author's code, the following solution works:

function bringFront(elem, stack){
    // Brings a file to the stack front
    var min, group = $.makeArray($(stack)).sort(function(a, b) {
        return (parseInt($(a).css("zIndex"), 10) || 0) - (parseInt($(b).css("zIndex"), 10) || 0);

    if(group.length < 1) return;
    min = parseInt(group[0].style.zIndex, 10) || 0;
    $(group).each(function(i) {
        this.style.zIndex = min+i;

    if(elem == undefined) return;
    $(elem).css({'zIndex' : min+group.length});


But it would be better to name the library method in some way.


source to share

2 answers

Found a solution by hacking jqery's draggable widget:

    var widget = $('#myDraggable').data('ui-draggable');




Have you just tried starting a draggable stack with a push?

 $('#target').on("click", function() {
       $( this ).draggable({ stack: "#products" });




All Articles